Forum Discussion

cdrgreg's avatar
cdrgreg
Copper Contributor
Apr 10, 2026

Table Styles and the Ribbon Table Design>Table Option Checkboxes

I have been dabbling in Word VBA for almost three decades but have a fairly limited practical use for Word so I rarely find myself dealing with Tables.

However, the other day I got interested in Charles Kenyon's post on creating a table style with VBA and that led to my discovery of some very odd behavior with both the Table Option Checkboxes on the Ribbon and table style visibility.  Specifically a) What triggers which of those six buttons is checked when a table style is applied, b) Why can't one or more of the plethora of "Table Styles" be removed from the Table Style Gallery on the Table Design Ribbon and c) Why can't the table style visibility be modified in the Style Manager "Recommended Dialong ("Show, Hide, Hide Until Used" is dimmed).

First, I took Charles' recorded macro and modified it to focused on only two conditional formatting object “Header Row” and “Total Row”

Option Explicit

Sub TableStyleCreate()

Dim oStyle As Style

Dim oTS As TableStyle

  On Error Resume Next

  If ActiveDocument.Tables.Count = 1 Then ActiveDocument.Tables(1).Delete 'For testing.

  DoEvents

  Set oStyle = ActiveDocument.Styles.Add("Table with Just One Condtional Style Element", wdStyleTypeTable)

  If Err.Number <> 0 Then

    'The named style already exists.  Delete it.

    ActiveDocument.Styles("Table with Just One Condtional Style Element").Delete

    DoEvents

    Set oStyle = ActiveDocument.Styles.Add("Table with Just One Condtional Style Element", wdStyleTypeTable)

  End If

  oStyle.BaseStyle = "Table Grid"

  On Error GoTo 0

  Set oTS = oStyle.Table

  With oTS.Condition(wdFirstRow) 'Associated with Header Row Checkbox

    .Shading.BackgroundPatternColor = wdColorLightTurquoise

    DefineBorder .Borders(wdBorderLeft), wdLineStyleSingle, wdLineWidth150pt, wdColor:=wdColorBlue

    DefineBorder .Borders(wdBorderRight), wdLineStyleSingle, wdLineWidth150pt, wdColorBlue

    DefineBorder .Borders(wdBorderTop), wdLineStyleSingle, wdLineWidth150pt, wdColorBlue

    DefineBorder .Borders(wdBorderBottom), wdLineStyleSingle, wdLineWidth150pt, wdColorBlue

    DefineBorder .Borders(wdBorderVertical), wdLineStyleSingle, wdLineWidth150pt, wdColorBlue

  End With

  With oTS.Condition(wdLastRow) 'Associated with Total Row Checkbox

    .Shading.BackgroundPatternColor = wdColorRose

    DefineBorder .Borders(wdBorderLeft), wdLineStyleSingle, wdLineWidth150pt, wdColorRed

    DefineBorder .Borders(wdBorderRight), wdLineStyleSingle, wdLineWidth150pt, wdColorRed

    DefineBorder .Borders(wdBorderTop), wdLineStyleSingle, wdLineWidth150pt, wdColorRed

    DefineBorder .Borders(wdBorderBottom), wdLineStyleSingle, wdLineWidth150pt, wdColorRed

    DefineBorder .Borders(wdBorderVertical), wdLineStyleSingle, wdLineWidth150pt, wdColorRed

  End With

  ActiveDocument.Tables.Add Selection.Range, 5, 7

  Selection.Tables(1).Style = "Table with Just One Condtional Style Element"

lbl_Exit:

  Exit Sub

End Sub

Sub DefineBorder(oBorder As Object, Optional LineStyle As WdLineStyle = wdLineStyleSingle, Optional LineWidth As WdLineWidth, _

                 Optional wdColor As wdColor = wdColorAutomatic)

  On Error Resume Next

  With oBorder

    .LineStyle = LineStyle

    .LineWidth = LineWidth

    .Color = wdColor

  End With

  On Error GoTo 0

lbl_Exit:

  Exit Sub

End Sub

TABLE STYLE OPTION CHECKBOXES

After the macro runs, there is a five row, seven column table inserted into the document with conditional formatting displayed only on the “Header Row.”

The reason for this is because when the table is inserted the Table Style Options on the Table Design tab are configured with “Header Row,  Last Column, and Banded Rows” checked with “Total Row, Last Column and Banded Columns” unchecked.

 

When I then checked “Total Row,” my style defined last row formatting was displayed.

My style is formatted with only “Header Row and Total Row” formatting.  Why was “First Column and Banded Rows” checked and “Total Row” not? I mean, if I go to the trouble of creating  a style with conditional formatting, it seems to reason that I would want to see that formatting applied when I apply that style to a table.  Why would I need to take the extra steps of selecting the table, clicking Table Design tab, and checking unchecked boxes?

While investigating, I read that:

"Set as Default" Function: If you modify a table (e.g., check "Total Row") and right-click to select "Set as Default," those specific check marks will appear on all future tables.

So, I selected the table, and checked “Header Row and Total” and unchecked the other four boxes, then selected the style in the Table Styles Gallery, right clicked and applied "Set as Default." I inserted another table, applied the style but still, the formatting was incorrect for the second table.  I had to again, select it, select Table Design and check the unchecked box for Total Row.

I also read that the default configuration of the Table Style Option buttons is set as Header Row, First Column and Banded Rows checked whenever a new table is inserted in a document.  That seems a bit illogical as I believe the default table style when a new table is inserted using Insert>Tables>Table is "Table Grid".  The built-in Table Grid style doesn't have conditional formatting applied to either the Header Row, First Column or Banded Rows.  One may wonder why are the boxes checked in that case?  But they are.

However, that theory is debunked because if you insert a table using a simple VBA procedure:

Sub InsertSimpleTable()

Dim oTbl As Table

   Set oTbl = ActiveDocument.Tables.Add(Selection.Range, 8, 6)

   MsgBox oTbl.Style.NameLocal

End Sub

... which again has no conditional formatting applied, the Table Style Option boxes checked are "Banded Rows" and "Banded Columns" (the Header Row and First Column boxes are unchecked).  Where is the logic in that?  What triggered this change?

It seems to me that the logical behavior would be that whenever a Conditional Formatting is defined in the table style that the associated Table Style Option button would be checked and the others unchecked when the table is inserted and that style applied.  If a user then wants to then turn off the display of one or more conditions, then they uncheck it.

 

Scenario: I need to create a document with 100 tables with conditional formatting applied to the Header Row and Total row.  First table contains 3 rows, the second 4 four rows, third 5 row … the one hundredth 102 rows.  I create a style with conditional Header and Total row formatting. I insert the first table apply the style, select the table, click Table Design Tab, check Total Row in table design options.  I shouldn’t have to repeat those ridiculous steps for each of the next 99 tables.  Madness!!

TABLE STYLES IN GENERAL

Next is table styles in general.  The Table Design>Table Gallery has a plethora (a hundred or more) table styles displayed.  Shauna Kelly discusses this absurdity in her page on tables styles (can't seem to post link) and how to remove some or all of them.

She is right.  Despite the artificial idiot solution to the prompt Word Table Design>Table Style Gallery remove a displayed style:

To remove a displayed table style from the gallery in Word, right-click the specific style in the Table Design tab's gallery and select Remove form Style Gallery. This instantly removes the style from view in the current document, although it remains available in the full style list.

There is no "Remove from Style Gallery" and as she states, there is no apparent way in the user interface to remove these built-in table table styles.

Unfortunately, her suggested VBA method for doing so (in which I think there are typos):

Sub HideATableStyleButMakeItVisibleWhenUsed()

  With ActiveDocument.Styles(Word.wdStyleTableLightShading)

    .Visibility = True 'Yes, True.

    .UnhideWhenUsed = True

  End With

End Sub

nor my altered version makes any difference.

Sub MyAlteredVersion()

  With ActiveDocument.Styles(Word.wdStyleTableLightGrid)

    .Visibility = False

    .UnhideWhenUsed = False

    .Hidden = True

  End With

lbl_Exit:

  Exit Sub

End Sub

At other places on the web, I have read that you can perhaps "hide" these styles with the Manage Styles "Restrict" dialog or Manage Styles "Recommended" Dialog.  I applied restriction to all List Tables styles and still all 49 List Table type styles doggedly persist in the Table Style gallery.

Attempts to hide using the visibility settings with the Style Manager Recommended Tab also fails:

You can select Table Styles that are visible in the Table Style Pane and try to make them hidden but the associated visibility buttons are dimmed.

All of my testing has been done with Word 2019.  Does anyone have any evidence that any of these oddities/anomalies are resolved in new versions?

Thank you. 

 

 

 

5 Replies

    • cdrgreg's avatar
      cdrgreg
      Copper Contributor

      What do you mean by "This is"

      Is it resolved in versions after 2019 or is it (by it meaning all the issues described) still broken?

      I am familiar with both links.  The code in both doesn't work.  Even if it did, the user would still have to select the table, select Table Design and check the box for Total Row and BandedColumns.   

    • cdrgreg's avatar
      cdrgreg
      Copper Contributor

      To get the code in the first link to actually work, you could combine the two.  Still the Banded Columns and Total Row formatting will not be applied:

      Sub ApplyConditionalStyle() With ActiveDocument .Tables(1).Select 'Assumes the table select is formatted with "Table Grid" style With .Styles("Table Grid").Table .ColumnStripe = 1 .RowStripe = 1 .Condition(wdOddColumnBanding).Shading _ .BackgroundPatternColor = wdColorGray10 .Condition(wdOddRowBanding).Shading _ .BackgroundPatternColor = wdColorGray10 .Condition(wdFirstRow).Borders(wdBorderBottom) _ .LineStyle = wdLineStyleDouble .Condition(wdFirstColumn).Borders(wdBorderRight) _ .LineStyle = wdLineStyleDouble .Condition(wdLastRow).Borders(wdBorderTop) _ .LineStyle = wdLineStyleDouble End With End With End Sub

       

    • cdrgreg's avatar
      cdrgreg
      Copper Contributor

      Kidd_Ip,

      I am familiar with the links.

      The code in the examples don't work.  If it did, it still doesn't display all of the the formatting the user obviously just wanted to see in his or her document with first selecting the table and then checking the box to display Column banding and Last Row.

      Utterly stupid functionality.

       

       

  • cdrgreg's avatar
    cdrgreg
    Copper Contributor

    I was unable to edit the original post.  The style name used in the original code should be "Table with Two Conditional Style Elements"

    The following shows the VBA steps to solve the scenario of inserting 100 unique tables with the desired style applied and the "desired" styled appearing as defined in the style it the document.  Imagine having to this through the UI:

    Sub MakeTables()
    Dim lngIndex As Long
      For lngIndex = 1 To 100
        With Selection
          'Add the table and apply the style
          ActiveDocument.Tables.Add .Range, 2 + lngIndex, 7
          .Tables(1).Style = "Table with Two Condtional Style Elements"
          'The following six steps replicates the tedious and ridiculous process of _
          selecting the table, select Table Design tab and setting the associated _
          Table Style Option checkboxes to match the actual table conditional formatting.
          .Tables(1).ApplyStyleHeadingRows = True
          .Tables(1).ApplyStyleLastRow = True
          .Tables(1).ApplyStyleFirstColumn = False
          .Tables(1).ApplyStyleLastColumn = False
          .Tables(1).ApplyStyleRowBands = False
          .Tables(1).ApplyStyleColumnBands = False
          'Prepare to insert next table
          .Tables(1).Range.Select
          .Collapse Direction:=wdCollapseEnd
          .InsertBefore vbCr
          .MoveDown Unit:=wdParagraph, Count:=1
        End With
      Next lngIndex
    lbl_Exit:
      Exit Sub
    End Sub

     I think the behavior of the Table Style Option checkboxes is the utterly stupid.  Showing checkboxes checked with a table that has no associated formatting is not only pointless, it is confusing.  Knowing nothing about the bizarre behavior of these button, a user might expect something to change if a checked box is unchecked and certainly would miss any emphasis intended when formatting is defined i.e., Total Row but the box is not checked.

    A more sensible behavior would be only boxes with associated conditional formatting defined is enabled and checked by default.  If a user does not want to see style defined emphasis let them turn if off after the table is inserted and the style is applied.  Not the other was around.