多语言展示
当前在线:1965今日阅读:167今日分享:16

Word 如何批量格式化表格样式以及批量添加题注

在Word文档中通常需要添加许多表格,这个时候可能各个表格的样式不一样并且没有添加题注。这个时候我们可以利用宏来进行批量调整,在表格多的时候非常有用哦!
工具/原料
1

WORD

2

方法/步骤
1

在word文档中找到视图——宏

2

随意输入一个宏名字,然后接下来是粘贴代码的时刻了!

3

Sub 批量修改表格()     Dim tempTable As table    Application.ScreenUpdating = False    If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then        MsgBox '文档已保护,此时不能选中多个表格!'        Exit Sub    End If    ActiveDocument.DeleteAllEditableRanges wdEditorEveryone    For Each tempTable In ActiveDocument.Tables        tempTable.Range.Editors.Add wdEditorEveryone    Next    ActiveDocument.SelectAllEditableRanges wdEditorEveryone    ActiveDocument.DeleteAllEditableRanges wdEditorEveryone    Application.ScreenUpdating = True    End SubSub FormatAllTables()For i = 1 To ActiveDocument.Tables.Count       ' ActiveDocument.Tables(i).Style = 'my'        With ActiveDocument.Tables(i).Range.ParagraphFormat        .LeftIndent = CentimetersToPoints(0)        .RightIndent = CentimetersToPoints(0)        .SpaceBefore = 0        .SpaceBeforeAuto = False        .SpaceAfter = 0        .SpaceAfterAuto = False        .LineSpacingRule = wdLineSpace1pt5        .Alignment = wdAlignParagraphJustify        .WidowControl = False        .KeepWithNext = False        .KeepTogether = False        .PageBreakBefore = False        .NoLineNumber = False        .Hyphenation = True        .FirstLineIndent = CentimetersToPoints(0)        .OutlineLevel = wdOutlineLevelBodyText        .CharacterUnitLeftIndent = 0        .CharacterUnitRightIndent = 0        .CharacterUnitFirstLineIndent = 0        .LineUnitBefore = 0        .LineUnitAfter = 0        .MirrorIndents = False        .TextboxTightWrap = wdTightNone        .AutoAdjustRightIndent = True        .DisableLineHeightGrid = False        .FarEastLineBreakControl = True        .WordWrap = True        .HangingPunctuation = True        .HalfWidthPunctuationOnTopOfLine = False        .AddSpaceBetweenFarEastAndAlpha = True        .AddSpaceBetweenFarEastAndDigit = True        .BaseLineAlignment = wdBaselineAlignAuto        End With        ' 设置表中的字体及大小        ActiveDocument.Tables(i).Select         With Selection         .Font.Size = 10         .Font.Name = '宋体'         .InsertCaption Label:='表格', TitleAutoText:='InsertCaption1', _             Title:='', Position:=wdCaptionPositionAbove, ExcludeLabel:=0        End With        ActiveDocument.Tables(i).Cell(1, 1).Select        With Selection         .SelectRow         .Font.Bold = True         .Shading.BackgroundPatternColor = -6         .ParagraphFormat.Alignment = wdAlignParagraphCenter        End With NextEnd Sub

注意事项

可以自己调节字体大小参数

推荐信息