在编写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
该宏用于批量设置Word文档中的表格样式,包括自动调整表格宽度、固定列宽、首行和首列的格式。它会将所有表格设置为固定列宽,首列加粗并设置为灰色背景,首行则设置为白色背景。用户可以自定义第一列的宽度值。
2247

被折叠的 条评论
为什么被折叠?



