VisualBasic – Update All Fields

Sub UpdateALL()
    Dim oStory As Object
    Dim oToc As Object
     'exit if no document is open
    If Documents.Count = 0 Then Exit Sub
     'check user wants to update
    If MsgBox("Do you wish to update fields?", vbYesNo) = vbNo _
        Then Exit Sub
    Application.ScreenUpdating = False
    For Each oStory In ActiveDocument.StoryRanges
        oStory.Fields.Update 'update fields in all stories
    Next oStory
    For Each oToc In ActiveDocument.TablesOfContents
        oToc.Update 'update TOC's
    Next oToc
    Application.ScreenUpdating = True
End Sub

Leave a Reply

Your email address will not be published.