一些闲言碎语

人有悔意,请天怜之。人有悔意,请天怜之。人有悔意,请天怜之。

使用表格样式进行批量调整表格格式

如果不知道表格样式的,可以去看一下解析Word——Word法宝「样式」之「表格样式」。

如果你Word文章中有许多表格的格式要调整成一致,建议你使用表格样式进行批量调整,而不是用格式刷去刷。比如你的文章中有很多表格,想调整为统一格式的三线表,你可以建立一种三线表式去调整。如下图所示:

使用【表格样式】+【全选表格】进行批量调整表格格式

本文将讲述如何使用VBA代码建立三线表样式

建立三线表表格样式代码

Sub 三线表表格样式()
    b = False
    Set MyDoc = ActiveDocument
    MyTableName = "三线表"
    For Each MyStyle In MyDoc.Styles
        If MyStyle.NameLocal = "三线表" Then
            Application.StatusBar = "该样式已存在!"
            Exit Sub
        Else
            b = False
        End If
    Next
    If b = False Then
    ActiveDocument.Styles.Add Name:=MyTableName, Type:=wdStyleTypeTable
'    整体表格字体设置
    With ActiveDocument.Styles(MyTableName).Font
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .NameOther = "Times New Roman"
        .Name = "Times New Roman"
        .Size = 10.5
    End With
'    整体表格段落设置
    With ActiveDocument.Styles(MyTableName).ParagraphFormat
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphCenter
        .SpaceAfter = 0
    End With
    With ActiveDocument.Styles(MyTableName).Table
        .Alignment = wdAlignRowCenter
        .AllowPageBreaks = True
        .AllowBreakAcrossPage = True
    End With
'    整体表格边框线设置
    With ActiveDocument.Styles(MyTableName).Table.Borders
        .OutsideLineStyle = False
        .InsideLineStyle = False
    End With
    With ActiveDocument.Styles(MyTableName).Table.Borders(wdBorderBottom)
        .LineStyle = wdLineStyleSingle
    End With
'    标题行边框设置
    With ActiveDocument.Styles(MyTableName).Table.Condition(wdFirstRow)
        With .Borders(wdBorderTop)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth050pt
        End With
        With .Borders(wdBorderBottom)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth050pt
        End With
    End With
'    标题行段落格式设置
    With ActiveDocument.Styles(MyTableName).Table.Condition(wdFirstRow). _
        ParagraphFormat
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphCenter
    End With
'    标题行字体格式设置
    With ActiveDocument.Styles(MyTableName).Table.Condition(wdFirstRow).Font
        .NameFarEast = "黑体"
        .NameAscii = "Times New Roman"
        .NameOther = "Times New Roman"
        .Name = "Times New Roman"
        .Size = 10.5
    End With
'    汇总行边框线设置
    With ActiveDocument.Styles(MyTableName).Table.Condition(wdLastRow).Borders(wdBorderBottom)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth050pt
    End With
'   汇总行段落格式设置
    With ActiveDocument.Styles(MyTableName).Table.Condition(wdLastRow).ParagraphFormat
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphCenter
    End With
'    汇总行字体格式设置
    With ActiveDocument.Styles(MyTableName).Table.Condition(wdLastRow).Font
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .NameOther = "Times New Roman"
        .Name = "Times New Roman"
        .Size = 10.5
    End With
    End If
    Application.StatusBar = "三线表表格样式新建完毕!"
End Sub

如何使用该代码?打开Word后,按下Alt+F11组合键,打开VBE窗口,将代码复制进VBE窗口中。

将代码复制到VBE窗口中

单击执行按钮,执行程序。程序执行完毕以后,如果成功建立样式,则在Word的状态栏会显示提示信息。

执行代码建立三线表样式

选中要调整的表格,为这些表格应用新建的【三线表】样式,即可批量为这些表格调整格式。

限时特惠:本站每日持续更新5-20节内部创业项目课程,一年会员
只需199元,全站资源免费下载点击查看详情
站长微信:
jjs406

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注