word 使用宏批量设置表格

本文介绍了一个使用VBA脚本批量修改Word文档中所有表格样式的示例代码。该脚本可以为表格设置内外边框样式及颜色,并调整表格及其内容的对齐方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sub ChangeTable()

Application.Browser.Target = wdBrowseTable

    For i = 1 To ActiveDocument.Tables.Count

        ActiveDocument.Tables.Item(i).Select

        With Selection
    
            '表格外边框
            .Borders.OutsideLineStyle = wdLineStyleSingle
            '表格内边框
            .Borders.InsideLineStyle = wdLineStyleSingle
            '表格内边框
            .Borders(wdBorderRight).Color = wdColorAutomatic
            .Borders(wdBorderLeft).Color = wdColorAutomatic
            .Borders(wdBorderTop).Color = wdColorAutomatic
            .Borders(wdBorderBottom).Color = wdColorAutomatic
            '表格居中
            .Rows.Alignment = wdAlignRowLeft
            '表格内容居中
            .Range.Paragraphs.Alignment = wdAlignParagraphLeft
            
        End With
    
    Next i

End Sub

 

相关链接:http://blog.chinaunix.net/uid-20423564-id-1949478.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值