Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Updating a Field in a Text Box.

Updating a Field in a Text Box

Written by Allen Wyatt (last updated July 15, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


Jay has a situation where he has a document property field inserted in a text box in a document. Using Ctrl+A and then pressing F9 should update all the property document fields in the document, but this one field is not updated by Jay's action. The process to update fields in headers and footers also does not update the field inside the text box. Jay is wondering if there is a way he can manually update the field using the keyboard or if there is a way to update it using a macro.

Fields can be placed in lots of document elements. They can be, for instance, in the main document text, in text boxes, in headers or footers, in AutoShapes, or in special tables. While pressing Ctrl+A will select all of your document, pressing F9 won't update the fields in all of the document elements. Instead, you need to use a macro to do the updating.

If you simply want a macro to update the fields in any of your text boxes, this is easy enough to do. The following macro steps through each of the shapes in your document (this includes text boxes and AutoShapes) and, if the shape contains text, update any fields it contains.

Sub UpdateTBFields()
    Dim shp As Shape

    For Each shp In ActiveDocument.Shapes
        With shp.TextFrame
            If .HasText Then
                .TextRange.Fields.Update
            End If
        End With
    Next
End Sub

This macro could be assigned to a keyboard shortcut so that you could easily update the fields with the touch of the shortcut. Of course, you might want to develop a more encompassing macro that updates all the fields, wherever they may be. (Remember—fields can be in any number of document elements.) In that case, consider the following more-encompassing version of the macro.

Public Sub UpdateAllFields()
    Dim doc As Document
    Dim wnd As Window
    Dim lngMain As Long
    Dim lngSplit As Long
    Dim lngActPane As Long
    Dim rngStory As Range
    Dim TOC As TableOfContents
    Dim TOA As TableOfAuthorities
    Dim TOF As TableOfFigures
    Dim shp As Shape

    ' Set Objects
    Set doc = ActiveDocument
    Set wnd = ActiveDocument.ActiveWindow

    ' get Active Pane Number
    lngActPane = wnd.ActivePane.Index

    ' Hold View Type of Main pane
    lngMain = wnd.Panes(1).View.Type

    ' Hold SplitSpecial
    lngSplit = wnd.View.SplitSpecial

    ' Get Rid of any split
    wnd.View.SplitSpecial = wdPaneNone

    ' Set View to Normal
    wnd.View.Type = wdNormalView

    ' Loop through each story in doc to update
    For Each rngStory In doc.StoryRanges
        If rngStory.StoryType = wdCommentsStory Then
            Application.DisplayAlerts = wdAlertsNone
            ' Update fields
            rngStory.Fields.Update
            Application.DisplayAlerts = wdAlertsAll
        Else
            ' Update fields
            rngStory.Fields.Update
        End If
    Next

    'Loop through text boxes and update
    For Each shp In doc.Shapes
        With shp.TextFrame
            If .HasText Then
                shp.TextFrame.TextRange.Fields.Update
            End If
        End With
    Next

    ' Loop through TOC and update
    For Each TOC In doc.TablesOfContents
        TOC.Update
    Next

    ' Loop through TOA and update
    For Each TOA In doc.TablesOfAuthorities
        TOA.Update
    Next

    ' Loop through TOF and update
    For Each TOF In doc.TablesOfFigures
        TOF.Update
    Next

    ' Return Split to original state
    wnd.View.SplitSpecial = lngSplit

    ' Return main pane to original state
    wnd.Panes(1).View.Type = lngMain

    ' Active proper pane
    wnd.Panes(lngActPane).Activate

    ' Close and release all pointers
    Set wnd = Nothing
    Set doc = Nothing
End Sub

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12344) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Updating a Field in a Text Box.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Removing Automatic Lines

Type a few dashes, underscores, or equal signs, and you could end up with a full-width line in your document. This is ...

Discover More

Printing All or Nothing

Want to make sure that when you worksheet is printed that everything in the workbook is really printed? You can ...

Discover More

Multiple Document Users

If you have a group of people working on a single document, you may wonder what tools are available in Word to facilitate ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Removing Specific Fields

Word allows you to place all sorts of fields in your documents. If you want to search for only specific types of fields, ...

Discover More

Controlling Field Shading

If you use fields in your documents, you may want to highlight them in some way so that you can find them easier. Word ...

Discover More

Updating Fields in Locked Forms

Updating form fields in Word can be confusing, especially when the fields are locked in a form. This tips explains why ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 - 3?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.