在编写word文档的过程中,有时候会使用很多的表格,执行如下宏,批量设置全部表格的样式
Sub 批量设置表格样式()
'
' 批量设置表格样式 Macro
'
On Error Resume Next
Dim t As Table
For Each t In ActiveDocument.Tables
't.AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格
't.AutoFitBehavior (wdAutoFitWindow) '根据窗口自动调整表格
t.AutoFitBehavior (wdAutoFitFixed) '固定列宽
t.Select
Selection.Cells.DistributeWidth
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns(1).PreferredWidth = CentimetersToPoints(2.5) '第1列宽度值(单位:厘米),可自行修改
't.Rows.First.Select
'Selection.Font.Bold = -1 '首行字体加粗 0 不加粗
't.Rows.First.Cells.Shading.BackgroundPatternColor = wdColorWhite '首行背景色
t.Columns.First.Select
Selection.Font.Bold = -1 '首列字体加粗
t.Columns.First.Cells.Shading.BackgroundPatternColor = wdColorGray30 '首列背景色
Next
Selection.HomeKey Unit:=wdStory
End Sub