Disclaimer: Kindly follow this tutorial carefully. I will not be held liable in any way for any misconfiguration mistakes that you, my dear reader, might make.
Note: In order for this to work, enabling macros in the options is a must. If you prefer not to enable macros, then this tutorial is not for you.
Follow the instructions below to add a Table of Contents update button to the Quick Access Toolbar in Microsoft Word (2013 and earlier), and make it work across all documents. By “all documents”, we mean documents that have been created, and documents that are going to be created on the same computer in the future. In reality, all fields such as the Table of Figures will be updated too, not just the Table of Contents, and that’s a good thing.
Let’s take it step by step
Create a new Word Document and open it.
Press ALT+F11 on the keyboard. This will open the Microsoft Visual Basic for Applications window. If you have trouble with the keyboard shortcut ALT+F11, activate the “Developer” tab by doing this:
– Click the File tab.
– Click Options.
– Click Customize Ribbon.
– Under Customize the Ribbon and under Main Tabs, select the Developer check box.
– In the Ribbon, click the Developer tab.
– Click Visual Basic
Again, this will open the Microsoft Visual Basic for Applications window.
In the left pane, navigate to “ThisDocument” under “Normal”, as follows:
Microsoft Word Objects
Double click on “ThisDocument”. An empty (most likely) VB script window will open.
Copy and paste the following code courtesy of Gilles into the VB editor that was just opened.
'' Update all the fields, indexes, etc. in the specified document. Sub UpdateAllFieldsIn(doc As Document) '' Update tables. We do this first so that they contain all '' necessary entries and so extend to their final number of '' pages. Dim toc As TableOfContents For Each toc In doc.TablesOfContents toc.Update Next toc Dim tof As TableOfFigures For Each tof In doc.TablesOfFigures tof.Update Next tof '' Update fields everywhere. This includes updates of page '' numbers in tables (but would not add or remove entries). '' This also takes care of all index updates. Dim sr As range For Each sr In doc.StoryRanges sr.Fields.Update While Not (sr.NextStoryRange Is Nothing) Set sr = sr.NextStoryRange '' FIXME: for footnotes, endnotes and comments, I get '' a pop-up "Word cannot undo this action. Do you want '' to continue?" sr.Fields.Update Wend Next sr End Sub '' Update all the fields, indexes, etc. in the active document. '' This is a parameterless sub-routine so that it can be used '' interactively. Sub UpdateAllFields() UpdateAllFieldsIn ActiveDocument End Sub
Save and close the Microsoft Visual Basic for Applications window.
Next, to add a Quick Access Toolbar button for convinience, navigate to the Quick Toolbar (next to the Undo & Redo buttons at the top left).
Click the little down arrow
From the drop-down menu, choose More Commands…
The “Word Options” dialogue box will appear. Under “Choose commands from:”, select “Macros”.
In the rectangular box under that, select the Macro with the name “Normal.ThisDocument.UpdateAllFields”.
Click the “Add” button in the middle of the dialogue box. It will be added to the rectangular box on the right side.
(Optional but recommended step). Click on Project.ThisDocument.UpdateAllFields
Click the button “Modify” at the button to change the symbol shape. Choose any symbol you fancy, and change the display name to whatever name you prefer. This name will be shown when you hover over the button in the Quick Access Toolbar. A name such as “Update All Fields” or “Update TOC” are some suggestions.
Click OK on the “Modify Button” dialogue box.
Click OK on the “Word Options” dialogue box.
Check that the button has been added at the top left in the Quick Access Toolbar.
Check the button’s functionality by creating a Table of Contents or a Table of Figures, then change a few things in the headers or figure captions, and click the button to see the updates reflected.
This must be done once on every computer you use. If you have a desktop and a laptop, you must do all the above on both machines if you desire to have this functionality on all your computers. The reason is that this a matter of personalizing Microsoft Word, and such customizations are saved independently on each machine.
Thank you for reading!