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
Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>