UpdateAutoFormat Method

Microsoft Word Visual Basic

UpdateAutoFormat Method

       

Updates the table with the characteristics of a predefined table format. For example, if you apply a table format with AutoFormat and then insert rows and columns, the table may no longer match the predefined look. UpdateAutoFormat restores the format.

expression.UpdateAutoFormat

expression   Required. An expression that returns a Table object.

Example

This example creates a table, applies a predefined format to it, adds a row, and then reapplies the predefined format.

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

This example restores the predefined format to the table that contains the insertion point.

If Selection.Information(wdWithInTable) = True Then
    Selection.Tables(1).UpdateAutoFormat
Else
    MsgBox "The insertion point is not in a table."
End If