使用预定义表格格式对表格格式进行更新。例如,如果在用“自动套用格式”命令对一个表格设置格式之后插入行和列,那么该表格会不再与预定义格式相匹配。用 UpdateAutoFormat 方法可重新设置该格式。
expression.UpdateAutoFormat
expression 必需。该表达式返回一个 Table 对象。
本示例创建一个表格并应用预定义格式,再添加一行,然后重新应用预定义格式。
Dim docNew As Document
Dim tableNew As Table
Set docNew = Documents.Add
Set tableNew = docNew.Tables.Add(Selection.Range, 5, 5)
With tableNew
.AutoFormat Format:=wdTableFormatColumns1
.Rows.Add BeforeRow:=tableNew.Rows(1)
End With
MsgBox "Click OK to reapply autoformatting."
tableNew.UpdateAutoFormat
本示例恢复插入点所在表格的预定义格式。
If Selection.Information(wdWithInTable) = True Then
Selection.Tables(1).UpdateAutoFormat
Else
MsgBox "The insertion point is not in a table."
End If