Home » Questions » Computers [ Ask a new question ]

How to make a Table of Content auto-update?

How to make a Table of Content auto-update?

I am using Word 2007, but saving my documents in .doc (as opposed to .docx) formats because that's company policy.

Asked by: Guest | Views: 53
Total answers/comments: 1
Guest [Entry]

"If there's a check mark on the option Tools > Options > Print > Update
fields (in Word 2007, Office button > Word Options > Display > Update fields
before printing), then going to Print Preview and back will update the
fields. But it's just as easy to press Ctrl+A and then F9.

If you're looking for something that doesn't need any user interaction at
all, then you need a macro.
An example of a macro to update all fields of type ToC is:

Sub TOCFieldUpdate() ' Written by
Charles Kyle Kenyon 27 January
2005 ' Field Updater - TOC
fields Dim oField As Field
On Error Resume Next For Each
oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update End If If
oField.Type = wdFieldTOA Then
oField.Update End If Next
oField End Sub

If you wish to periodically execute the above macro, here's another macro for that.
that will update the ToC every 5 minutes:

Public Sub ToCUpdate()
Call TOCFieldUpdate
Application.OnTime When:=Now + TimeValue(""00:05:00""),
name:=""ToCUpdate"" End Sub

You can assign this macro to an icon or a hotkey. I wouldn't suggest to make it run automatically when the document opens, as you would run against the latest security safeguards of Microsoft.

Note: The above is untested, and even worse, is my very first attempt in writing VBA."