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

Preventing a Frame when Converting a Table to Text

Tables, in Word, can either be inline with the rest of your text or the text can wrap around the table. If you have ...

Discover More

Freezing Worksheet Tabs

If you have a lot of worksheets in a workbook, you may wonder if you can "freeze" the position of some of those worksheet ...

Discover More

Removing Dashes from ISBN Numbers

ISBN numbers are used to denote a unique identifier for a published book. If you remove the dashes included in an ISBN, ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Using Fields for Fractions

Want a quick way to create fractions? You can do it by using fields, as described in this tip.

Discover More

Inserting Summary Information

Want to insert into your document those snippets of information that you know Word maintains about your document? It's ...

Discover More

Monday's Date on Friday's Report

Automatically putting today's date at the top of a report is easy. Putting a different date, automatically, can be more ...

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 8 - 5?

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.