Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
MS Office Word VBA Macro to update all fields including in header and footer also update Table of Contents. Tracking Changes is disabled during the update.
Sub UpdateAllFieldsTOCWithoutTracking()
' Update All Fields and TOC without Tracking Changes for it:
' References:
' or
Dim oStory As Range
Dim isChangesTracked As Boolean
' Toggle off Track Changes
isChangesTracked = ActiveDocument.TrackRevisions
If isChangesTracked Then
ActiveDocument.TrackRevisions = False
End If
' Update Fields
For Each oStory In ActiveDocument.StoryRanges
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
End If
Next oStory
Set oStory = Nothing
' Update TableOfContents
If ActiveDocument.TablesOfContents.Count = 1 Then
End If
' Restore Changes Tracking
If isChangesTracked Then
ActiveDocument.TrackRevisions = True
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment