Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Updating an Entire TOC from a Macro.

Updating an Entire TOC from a Macro

Written by Allen Wyatt (last updated November 16, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


If you have a document that contains a table of contents (TOC), and you update the fields in the entire document, Word asks if you want to update the entire table, the chapter entries, or just the page numbers associated with the existing chapter entries in the Table of Contents. This occurs because TOCs are implemented through the use of a field, and when you update all fields you are telling Word you also want to update the field underlying the TOC.

You can update a TOC using a macro by utilizing the TablesOfContents collection. Each item in the collection represents a single TOC in the document. (In most documents the collection will consist of only a single item.) To update the entire TOC, you use this format of the command:

ActiveDocument.TablesOfContents(1).Update

The Update method is what does the work; it updates the TOC. If you want to update only the page numbers in the TOC, you use an entirely different method:

ActiveDocument.TablesOfContents(1).UpdatePageNumbers

Whenever you use commands like these in a macro, it is a good idea to make sure that there is actually a TOC in the document before you try to do any updating. The easiest way to do this is to just check the Count property for the collection, as shown here:

If ActiveDocument.TablesOfContents.Count = 1 Then _ 
  ActiveDocument.TablesOfContents(1).Update

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 (8621) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Updating an Entire TOC from a Macro.

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

Restoring a Keyboard Shortcut

Word uses keyboard shortcuts for all sorts of tasks. Sometimes you may create a shortcut that messes up one of the other ...

Discover More

Converting Numbers Into Words

Write out a check and you need to include the digits for the amount of the check and the value of the check written out ...

Discover More

Displaying Images based on a Result

Got some images that you want to appear in a worksheet based on the result displayed in a cell? Figuring out how to ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Locking Lines in a TOC

Want to "lock down" the lines in a TOC so that you cannot add new paragraph marks in the middle of one? You may not be ...

Discover More

Page Ranges in a TOC

It is easy to generate a table of contents for a document, and that TOC can contain page number references for each ...

Discover More

Creating a TOC that Includes Specific Styles

Want to create a special TOC that contains different elements of your document? It's easy to do if you consistently use ...

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 one less than 9?

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.