Style![]() ![]() ![]() |
该对象代表可应用于表格的单独的样式。
使用 Styles 对象的 Table 属性可返回 TableStyle 对象。使用 Borders 属性可为整张表格添加边框。使用 Condition 方法可以仅为表格的指定部分添加边框或底纹。本示例创建新的表格样式并将其格式设为具有四周边框。在表格的第一行、最后一行和最后一列应用特定的边框和底纹。
Sub NewTableStyle()
Dim styTable As Style
Set styTable = ActiveDocument.Styles.Add( _
Name:="TableStyle 1", Type:=wdStyleTypeTable)
With styTable.Table
'Apply borders around table
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
'Apply a double border to the heading row
.Condition(wdFirstRow).Borders(wdBorderBottom) _
.LineStyle = wdLineStyleDouble
'Apply a double border to the last column
.Condition(wdLastColumn).Borders(wdBorderLeft) _
.LineStyle = wdLineStyleDouble
'Apply shading to last row
.Condition(wdLastRow).Shading _
.BackgroundPatternColor = wdColorGray125
End With
End Sub