TableStyle object (Word)

Represents a single style that can be applied to a table.

Remarks

Use the Table property of the Styles object to return a TableStyle object. Use the Borders property to apply borders to an entire table. Use the Condition method to apply borders or shading only to specified sections of a table. This example creates a new table style and formats the table with a surrounding border. Special borders and shading are applied to the first and last rows and the last column.

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

Methods

Name
Condition

Properties

Name
Alignment
AllowBreakAcrossPage
AllowPageBreaks
Application
Borders
BottomPadding
ColumnStripe
Creator
LeftIndent
LeftPadding
Parent
RightPadding
RowStripe
Shading
Spacing
TableDirection
TopPadding

See also

Word Object Model Reference

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.