Applying the Correct Table Style to All Tables in a Document

Written by Allen Wyatt (last updated June 6, 2026)

Dennis has two custom table styles that he's created. One style (ShortTable) is used for shorter tables and the other (LongTable) is for longer tables. Dennis wonders if there is a way to step through each table in a document and automatically apply the correct style for each table. If a table has 7 or fewer body rows it should use the ShortTable style and longer tables should use the LongTable style.

The easiest way to accomplish this task is to use a macro. The following will do the trick, as it steps through each table in a document and applies the appropriate table style:

Sub ApplyTableStyles()
    Dim tbl As Table
    Dim bodyRows As Long
    Dim styShort As Style
    Dim styLong As Style
    Dim sMsg As String

    On Error Resume Next
    Set styShort = ActiveDocument.Styles("ShortTable")
    Set styLong = ActiveDocument.Styles("LongTable")
    On Error GoTo 0

    sMsg = ""
    If styShort Is Nothing Then
        sMsg = "Style ShortTable does not exist."
    Else
        If styShort.Type <> wdStyleTypeTable Then
            sMsg = "Style ShortTable is not a table style."
        End If
    End If
    If styLong Is Nothing Then
        If sMsg > "" Then sMsg = sMsg & vbCr
        sMsg = sMsg & "Style LongTable does not exist."
    Else
        If styLong.Type <> wdStyleTypeTable Then
            If sMsg > "" Then sMsg = sMsg & vbCr
            sMsg = sMsg & "Style LongTable is not a table style."
        End If
    End If
    If sMsg > "" Then
        MsgBox sMsg, vbExclamation
        Exit Sub
    End If

    For Each tbl In ActiveDocument.Tables
        bodyRows = tbl.Rows.Count

        ' Adjust row count if first row is a heading row
        If tbl.Rows(1).HeadingFormat = True Then bodyRows = bodyRows - 1

        If bodyRows <= 7 Then
            tbl.Style = styShort
        Else
            tbl.Style = styLong
        End If
    Next tbl
End Sub

Note that at the very beginning of the macro the two table styles are set into the styShort and styLong variables. This is done because if either style is set to nothing, it means that the style doesn't exist. (It does no good to step through the tables and try to apply non-existent styles.)

In addition, both styShort and styLong are checked to ensure that they are actually table styles, as Word will generate an error if you try to apply a different type of style (such as a paragraph style or a character style) to a table.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8522) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Selecting a Custom Chart

Microsoft Graph allows you to easily create charts from numeric data, without the need to use Excel. Here's how to use ...

Discover More

Setting the Calculation Default

Excel can recalculate your worksheets either automatically or manually. The default is to calculate them automatically, ...

Discover More

Formatting Currency

If you want to format currency values so that Excel uses periods between groups of thousands and commas as a decimal ...

Discover More

Discover the Power of Microsoft Office This beginner-friendly guide reveals the expert tips and strategies you need to skyrocket your productivity and use Office 365 like a pro. Mastering software like Word, Excel, and PowerPoint is essential to be more efficient and advance your career. Simple lessons guide you through every step, providing the knowledge you need to get started. Check out Microsoft Office 365 For Beginners today!

More WordTips (ribbon)

Inconsistent Repeating of a Table Header Row

When you have a table that extends over multiple pages, you may want to have Word repeat a row or two at the top of each ...

Discover More

Converting Tables to Text

Need to convert all the tables in your document into plain text? This tip provides a macro that can make quick work of a ...

Discover More

Entering Tabs in a Table

When you press the Tab key while entering info into a table, Word dutifully moves to the next table cell. If you don't ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three more than 4?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.