如何批量处理word中的表格
作者:互联网
如何批量处理word中的表格
1 . 批量设置word中的表格宽度
比如,我这有一个word文档有200多个表格(全部是3列的),现在要求第一列宽度3cm,第二列4cm,第三列5cm。一个一个改不太可能吧???执行如下的宏代码就搞定:
点击(此处)折叠或打开
- Sub Macro1()
- Dim MyTable As Table
- For Each MyTable In ActiveDocument.Tables
- MyTable.PreferredWidth = CentimetersToPoints(16)
- MyTable.Columns(1).PreferredWidth = CentimetersToPoints(3)
- MyTable.Columns(2).PreferredWidth = CentimetersToPoints(4)
- MyTable.Columns(3).PreferredWidth = CentimetersToPoints(5)
- Next
- End Sub
2. word中批量选中所有的表格
执行如下的宏代码即可:
点击(此处)折叠或打开
- Sub select_all_tables()
- Dim mytable As Table
- Application.ScreenUpdating = False
- For Each mytable In ActiveDocument.Tables
- mytable.Range.Editors.Add wdEditorEveryone
- Next
- ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
- ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
- Application.ScreenUpdating = True
- End Sub
方便大家查看,这里给出 word中批量选中所有的表格 例子,第一个类似:
按快捷键 ALT+F11后,
运行宏代码之后就选定了
3、 让word中所有的表格按照页面宽度调整
点击(此处)折叠或打开
- Private Sub Document_New()
- End Sub
- Private Sub Document_Open()
- 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 '垂直居中
- Next i
- End Sub
标签:Tables,word,表格,批量,MyTable,ActiveDocument,Sub 来源: https://blog.51cto.com/lhrbest/2695534