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.
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:
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.
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!
You can use the Advance field to change where text is positioned in your document. This tip shows how to use it and the ...
Discover MoreTired of messing with inserting the date and then changing it to a format that is more to your liking? There's a quick ...
Discover MoreWhen adding page numbers to a header or footer, you may find it helpful to modify how Word determines its "Page X of Y" ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments