Forum Discussion

Hakana's avatar
Hakana
Copper Contributor
Mar 28, 2026

Word VBA, Unreachable table style setting?

I've noticed something that may be a missing feature in the Word VBA Object model.

Styles in word can be of different kinds set by the WdStyleType when adding a style via expression.Add (Name, Type) method of the Styles Object (https://learn.microsoft.com/en-us/office/vba/api/word.styles.add).

Using

wdStyleTypeTable

 gives a Table Style.

Table styles differ somewhat from other styles since you build up the style of a table by setting the formatting for different parts/features of the table. E.g. the first, or last row may differ in their style compared to the rest of the table.

These kind of settings are reached via the Condition method of the TableStyle object (reachable from the Style.Table property).

Specifying different "conditions" (of data type WdConditionCode) give you access to ConditionalStyle objects handling the settings for different parts of the table.

In word you can modify the table styles by for example <right-clicking> a table style and selecting "Modify Table Style"

This presents you with the following UI.

Modify Style, Table edition.

The setting I am unable to reach via VBA is tied to the Condition "First Row" which can be reached by selecting the pull-down menu "Apply formatting to:" to Header Row, then clicking the button menu "Format" at the lower left and selecting "Table Properties...".

This gives us the "Table Properties" UI in which we in the tab "Row" is given the options to enable "Repeat as header row at the top of each page".

The effect of this can be seen in the "Description field" in the previous "Modify Style (Table Edition)" view. (You might have to select something else in "!Apply formatting to:" menu and then re-select "Header row" again to get the description field to update).

We now have a "Repeat as header row" shown in the description for "Header rows".

This is a setting which in VBA can be reached for an inserted Table via a Rows property:

table.rows.HeadingFormat

https://learn.microsoft.com/en-us/office/vba/api/word.row.headingformat

However, it should be possible to set for the table style as well.

In the resulting XML file (styles.xml) of the .docx file we find it in a <w:trPr> block as a <w:tblHeader/> tag.

Note that this is the definition of a style in the styles.xml, not the declaration of an inserted table.

 

Have anyone managed to reach this style setting via VBA or know of how it can be done?

I've scanned through the methods and properties of Style, TableStyle, and ConditionalStyle object definitions and not found anything allowing me to set this "Table property" as part of the style. It would make most sense if it was available in the TableStyle object (https://learn.microsoft.com/en-us/office/vba/api/word.tablestyle) since that is where properties such as "AllowBreakAcrossPage" can be found.

Maybe something they missed in the Word VBA model.

 

 

 

8 Replies

  • Hakana's avatar
    Hakana
    Copper Contributor

    While I still would call it a "bug" in that the object model does not include a way to reach the setting I sought to control, I have found a workaround.

    It lets VBA "makes the change via UI" by sending a set of "key-presses" just before opening up part of the UI. Not the prettiest of solutions but still...

    Sub SetHeaderRepeat(sty As String)
        ' This is a strange function. It is necessary since I have found no way of
        ' reaching the "Repeat as header row" setting in a Table Style using VBA.
        ' It can only be made through UI. The trick is to send a number of
        ' keyboard commands and then open a UI Dilogue. This makes word
        ' execute the Keyboard strokes.( % represents key 'ALT' and ~ is Enter.)
        
        Dim dia As Dialog
            Set dia = Dialogs(WdWordDialog.wdDialogFormatStyle)
        SendKeys "%S"
        SendKeys sty
        SendKeys "%M"
        SendKeys "%o"
        SendKeys "~"
        SendKeys "%h"
        SendKeys "~~"
        SendKeys "{Esc}"
        With dia
            .Show
        End With
    End Sub

     

  • Charles_Kenyon's avatar
    Charles_Kenyon
    Bronze Contributor

    I do not know that this will help, but here is a sample that I recorded when creating a new Table Style following John Korchok's directions on my Tables page.  

    https://answers.microsoft.com/en-us/msoffice/forum/all/editing-word-table-styles/92207096-eaa7-4ebf-81b2-7bc9f64d4c40 

    Table Styles Complete by John Korchok

    Sub StyleTableStyleCreate()
    '
    ' StyleTableStyleCreate Macro
    '
    '
        ActiveDocument.Styles.Add Name:="Table Style Custom Grid 1", Type:= _
            wdStyleTypeTable
        With ActiveDocument.Styles("Table Style Custom Grid 1").Font
            .Name = "+Body"
            .Size = 11
            .Bold = False
            .Italic = False
            .Underline = wdUnderlineNone
            .UnderlineColor = wdColorAutomatic
            .StrikeThrough = False
            .DoubleStrikeThrough = False
            .Outline = False
            .Emboss = False
            .Shadow = False
            .Hidden = False
            .SmallCaps = False
            .AllCaps = False
            .Color = wdColorAutomatic
            .Engrave = False
            .Superscript = False
            .Subscript = False
            .Scaling = 100
            .Kerning = 0
            .Animation = wdAnimationNone
            .Ligatures = wdLigaturesStandardContextual
            .NumberSpacing = wdNumberSpacingDefault
            .NumberForm = wdNumberFormDefault
            .StylisticSet = wdStylisticSetDefault
            .ContextualAlternates = 0
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").ParagraphFormat. _
            TabStops.ClearAll
        ActiveDocument.Styles("Table Style Custom Grid 1").Frame.Delete
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table
            .TableDirection = 1
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
            .Alignment = wdAlignRowLeft
            .Spacing = 0
            .AllowPageBreaks = True
            .AllowBreakAcrossPage = True
            .LeftIndent = InchesToPoints(0)
            .RowStripe = 1
            .ColumnStripe = 1
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = wdColorAutomatic
            End With
            With .Borders(wdBorderLeft)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderRight)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderTop)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderBottom)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderHorizontal)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderVertical)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstRow)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstRow)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577537
            End With
            With .Borders(wdBorderLeft)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderRight)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderTop)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstRow).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstRow).Font
            .Name = ""
            .Bold = True
            .Color = -603914241
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstRow).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastRow)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastRow)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577537
            End With
            With .Borders(wdBorderLeft)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderRight)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            With .Borders(wdBorderBottom)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastRow).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastRow).Font
            .Name = ""
            .Bold = True
            .Color = -603914241
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastRow).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstColumn)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstColumn)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577537
            End With
            With .Borders(wdBorderLeft)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            With .Borders(wdBorderTop)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderBottom)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstColumn).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstColumn).Font
            .Name = ""
            .Bold = True
            .Color = -603914241
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdFirstColumn).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastColumn)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastColumn)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577537
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            With .Borders(wdBorderRight)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderTop)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            With .Borders(wdBorderBottom)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
                .Color = -603914241
            End With
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastColumn).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastColumn).Font
            .Name = ""
            .Bold = True
            .Color = -603914241
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdLastColumn).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddColumnBanding)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddColumnBanding)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577690
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddColumnBanding).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddColumnBanding).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddColumnBanding).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenColumnBanding)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenColumnBanding)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577741
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenColumnBanding).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenColumnBanding).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenColumnBanding).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddRowBanding)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddRowBanding)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577690
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderVertical).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddRowBanding).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddRowBanding).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdOddRowBanding).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenRowBanding)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenRowBanding)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577741
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderVertical).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenRowBanding).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenRowBanding).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdEvenRowBanding).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNECell)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNECell)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577741
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNECell).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNECell).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNECell).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNWCell)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNWCell)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577741
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNWCell).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNWCell).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdNWCell).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSECell)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSECell)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577741
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSECell).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSECell).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSECell).ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSWCell)
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0.08)
            .RightPadding = InchesToPoints(0.08)
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSWCell)
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = -704577741
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders.Shadow = False
        End With
        With ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSWCell).ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
            .CollapsedByDefault = False
        End With
        ActiveDocument.Styles("Table Style Custom Grid 1"). _
            NoSpaceBetweenParagraphsOfSameStyle = False
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSWCell).Font.Name = ""
        ActiveDocument.Styles("Table Style Custom Grid 1").Table.Condition( _
            wdSWCell).ParagraphFormat.TabStops.ClearAll
    End Sub

    Does that  address the attributes you want to change?

    See the links in my previous reply.

     

    • Hakana's avatar
      Hakana
      Copper Contributor

      Aye, as cdrgreg noted. The setting I'm looking for is not recorded. (I tried the record macro earlier as well to see if there was a hidden Property or method that I had missed).

      I've posted a workaround further down.

       

    • cdrgreg's avatar
      cdrgreg
      Copper Contributor

      Charles,

         Thanks for posting the code.  No, it doesn't address the issue the OP is having but interesting nonetheless.  I tried to create a new thread here but couldn't figure out how.  Please see:

      https://www.msofficeforums.com/word-vba/54072-vba-table-style-creations-table-style-options.html#post188576

       

  • Charles_Kenyon's avatar
    Charles_Kenyon
    Bronze Contributor

    Like Doug Robbins, I am not sure why you would be trying to use VBA to create a Style. {I've done this to create character styles without many characteristics like the font so only on characteristic like the language is changed.) Have you tried recording a macro setting up your table style. This may be completely a waste of time, or it may give you insight into otherwise undocumented or poorly documented parts of the object model. 

  • Charles_Kenyon's avatar
    Charles_Kenyon
    Bronze Contributor

    There is a lot missing from the vba object model and there are some things that are just quirky. Table styles and vba have long had problems. See https://shaunakelly.com/word/tag/table-styles.html 

     I think that developers have given up on updating it. I'm just glad that they have not completely removed vba. I agree with Doug that you should use Feedback.

    The simplest way to create a new style is to create it in a template and create new documents based on the template within the UI. I do not know whether or not a custom Table Style gets brought into a document through a Quick Table that uses it, but it would be worth a try. Quick Tables

  • I am not sure why you would be trying to use VBA to create a Style. 

     However, it is a fact that VBA has not kept up with quite a number of the newer features of Word.

    If you want to try and have something done about it, go to Help>Feedback.

    • Hakana's avatar
      Hakana
      Copper Contributor

      I'm trying to achieve some kind of "Word-templates As Code", i.e. having "template specifications" that can be managed by configuration management tools e.g. git or similar. (Sure, even with VBA code I'm  'trapped' inside Word...).

      The bulk of the code will represent our "base template", and then there will be code to generate specific templates for specific document types. If there is a change to the base template it only needs to be changed in the code once rather than in all separate template files... 

      ... that plus that that I can't help but to enjoy the challenge 😀.

      I have posted Feedback via Help>Feedback. Wanted to check here first if I was missing something obvious.