手机版 欢迎访问it开发者社区(www.mfbz.cn)网站

当前位置: > 开发

word批量处理

时间:2021/5/21 10:39:57|来源:|点击: 次

第一行第一列居中对齐,表格里其他内容,居有对齐

Sub test()

'

' test 宏

'

On Error Resume Next

Application.Browser.Target = wdBrowseTable

 

For i = 1 To ActiveDocument.Tables.Count

 

    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格

    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitWindow) '根据窗口自动调整表格

    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中

    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalCenter '垂直居中

    For j = 2 To ActiveDocument.Tables(i).Rows.Count

        For k = 2 To ActiveDocument.Tables(i).Rows(j).Cells.Count

            ActiveDocument.Tables(i).Rows(j).Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft

        Next k

    Next j

Next i

 

End Sub

Sub test()
'
' test 宏
'
On Error Resume Next
Application.Browser.Target = wdBrowseTable

For i = 1 To ActiveDocument.Tables.Count

    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格
    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitWindow) '根据窗口自动调整表格
    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中
    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalCenter '垂直居中
    For j = 2 To ActiveDocument.Tables(i).Rows.Count
        For k = 2 To ActiveDocument.Tables(i).Rows(j).Cells.Count
            ActiveDocument.Tables(i).Rows(j).Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
        Next k
    Next j
Next i

End Sub

 

将所有的表格格式按照表格来设置,所有表格里段落的内容按着表格-规则来设置

Sub 宏2()

'

' 宏2 宏

'

   

On Error Resume Next

Application.Browser.Target = wdBrowseTable

 

For i = 1 To ActiveDocument.Tables.Count

 

    ActiveDocument.Tables(i).Style = ActiveDocument.Styles("表格")

    ActiveDocument.Tables(i).Style = "表格-规则"

    ActiveDocument.Tables(i).Range.Style = ActiveDocument.Styles("表格")

    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格

    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitWindow) '根据窗口自动调整表格

    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中

    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalCenter '垂直居中

 

Next i

End Sub

给word里所有的表格加上题注

Sub 宏6()

'

' 宏6 宏

'

'

On Error Resume Next

Application.Browser.Target = wdBrowseTable

 

For i = 1 To ActiveDocument.Tables.Count

 

    ActiveDocument.Tables(i).Range.InsertCaption Label:="表格", TitleAutoText:="InsertCaption2", _

        Title:="", Position:=wdCaptionPositionAbove, ExcludeLabel:=0

   

Next i

       

End Sub

图片插入题注

Sub 宏2()

'

' 宏2 宏

'

   

On Error Resume Next

Application.Browser.Target = wdBrowseTable

 

    For Each ils In ActiveDocument.InlineShapes

        ils.Select

        Selection.InsertCaption Label:="图表", TitleAutoText:="InsertCaption4", _

        Title:="", Position:=wdCaptionPositionBelow, ExcludeLabel:=0

    Next ils

 

End Sub

Copyright © 2002-2019 某某自媒体运营 版权所有