I want a way of updating all fields in a Word 2013 document. (If it works in other versions, all the better; I originally had this problem with Word 2007, and nothing seems to have changed since then.) This includes cross-references, page numbers, tables of contents, indexes, headers, etc. If it can be updated by pressing F9, I want it updated.

(In theory updating fields can cause other fields to need updating, e.g. a longer table of contents changes some page numbers in the main text. Taking care of the common cases is good enough for me. In fact, it's ok if I have to run the macro two or three times before it stabilizes. I just want to have a single macro that finds everything.)

My attempt so far doesn't update fields in text boxes inside figures. How do I update them, and what else have I missed?

EDIT: Combining the answer given with what I already had gives a macro that seems to update everything (with a known defect).

'' Update all the fields, indexes, etc. in the specified document.
Sub UpdateAllFieldsIn(doc As Document)
    '' Update tables. We do this first so that they contain all necessary
    '' entries and so extend to their final number of pages.
    Dim toc As TableOfContents
    For Each toc In doc.TablesOfContents
    Next toc
    Dim tof As TableOfFigures
    For Each tof In doc.TablesOfFigures
    Next tof
    '' Update fields everywhere. This includes updates of page numbers in
    '' tables (but would not add or remove entries). This also takes care of
    '' all index updates.
    Dim sr As range
    For Each sr In doc.StoryRanges
        While Not (sr.NextStoryRange Is Nothing)
            Set sr = sr.NextStoryRange
            '' FIXME: for footnotes, endnotes and comments, I get a pop-up
            '' "Word cannot undo this action. Do you want to continue?"
    Next sr
End Sub
'' Update all the fields, indexes, etc. in the active document.
'' This is a parameterless subroutine so that it can be used interactively.
Sub UpdateAllFields()
    UpdateAllFieldsIn ActiveDocument
End Sub
  • 1
    For completeness you may also want to add the table of authorities: Dim toa As Word.TableOfAuthorities / For Each toa In ActiveDocument.TablesOfAuthorities / toa.Update / Next – Terrance Feb 14 '13 at 19:29
  • Just a heads up that I tried this in Word 2013, and confirming that it still works. Thank you very much @Gilles for providing the code! – Ugo May 26 '15 at 9:48
  • What about a macro that goes to print preview and back to the document? – Pedro77 Aug 7 '15 at 12:57
  • @Pedro77 How is that supposed to help? At least with Word 2013 (I no longer have access to Word 2007), going to print preview, or for that matter printing, doesn't update fields. – Gilles 'SO- stop being evil' Aug 7 '15 at 14:17
  • My fields are updated, at least references and cross-reference fields. – Pedro77 Aug 7 '15 at 18:08

Go into the print settings, select update fields. Then go to print, or print preview your doc.

Et voilà, all fields are updated!

MS Word Print Options from Word of Mac 2016

  • 2
    Working for me now in Word 2010 (where the setting is in“File → Options → Display”). In fact without the option some fields are updated but not all. I'm pretty sure it didn't in Word 2007 but I no longer have it to test. – Gilles 'SO- stop being evil' Sep 15 '15 at 14:51
  • 2
    I'm on Word 2016 for Mac. The setting is in Word -> Preferences -> Print. But on widows it will in the print section of the global settings. I'm sure I've been there in the past, but I don't have an install to test with right now. – David Roussel Sep 15 '15 at 15:55
  • I guess this doesn't work anymore on Word 2016. – TCB13 Jan 7 '16 at 16:34
  • This worked for me in Word 2016 on Windows 7. – bouvierr Sep 27 '16 at 15:33
  • 1
    Pretending to print works with Word 2010. Not so intuitive… – M. Toya Dec 10 '18 at 9:11

I just do Ctrl+A - to select everything - and then F9 to update the lot.

Although, this misses headers and footers, but they update when you print/print-preview IIRC.


I've found the following macro. On a quick test it updated tables of contents, fields within paragraphs, fields within the header and footer, and fields within a floating text box figure.

Hopefully that covers everything that you need, if not please indicate what is still failing to update.

Source: http://www.gmayor.com/installing_macro.htm

Sub UpdateAll()
    Dim oStory As Range
    For Each oStory In ActiveDocument.StoryRanges
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
        End If
    Next oStory
    Set oStory = Nothing
End Sub
  • @Giles - OK, fair enough, always best to check that the basics have been explored first. I've just now had a hunt and found a macro that seems to do the job, check my update, let me know if it misses anything. – DMA57361 Oct 7 '10 at 8:10
  • Now we're talking! I have no idea why iterating with NextStoryRange and with document.StoryRanges are different things, but your code combined with the table updates I already had make up a winner (well, almost, but that's a different issue). – Gilles 'SO- stop being evil' Oct 7 '10 at 19:02
  • This does not work for fields contained in text boxes contained in the header / footer. Checked on Word 2016 – slobo Jun 8 '19 at 19:00

This page looks interesting:

If you are using Word 2007, the process is a bit different: Click the Office button and then click Word Options. Word displays the Word Options dialog box. Click on Advanced at the left side of the dialog box. (Click here to see a related figure.) In the General area (scroll down a bit to see it), make sure the Update Automatic Links at Open check box is selected. Click on OK. That setting should make sure that all your links are always up to date. If you want to update the fields when the document is opened, you'll need to use a macro to accomplish the task. Specifically, you'll need to use either an AutoOpen or AutoClose macro, depending on whether you want to update the fields when the document opens or closes. The following is an example of an AutoOpen macro you can use.

Sub AutoOpen()
    With Options
        .UpdateFieldsAtPrint = True
        .UpdateLinksAtPrint = True
    End With
End Sub

Note that the macro makes sure that the options are set to force updating the fields and links when printing occurs, then it updates all the members of the Fields collection in the document. If you, instead, wanted to update the fields at closing, you could use this macro:

Sub AutoClose()
End Sub

This macro is much shorter because there is no need to set the update-on-print options when you are exiting the document.exiting the document.


Word 2010:

Right click the ribbon, customise the ribbon, choose command from "all commands" search for "update" and add it where you want.

This button updates only selected fields.
Then, to update all fields, press Ctrl + A then this button.

  • How does it differ from pressing F9? Does that really update inside figures, tables, etc? – Gilles 'SO- stop being evil' Jul 18 '13 at 19:44
  • 1
    I now have Word 2013, so I checked. This appears to do the same as pressing F9. It doesn't update fields inside figures, which was my main motivation for asking this question. – Gilles 'SO- stop being evil' Aug 7 '15 at 14:13

If you want to properly update all headers and footers, this worked for me:

    Dim oStory As Range
    Dim oSection As Object
    Dim oHeader As Object
    Dim oFooter As Object

    For Each oStory In ActiveDocument.StoryRanges
    Next oStory

        For Each oSection In ActiveDocument.Sections
             For Each oHeader In oSection.Headers
             Next oHeader

             For Each oFooter In oSection.Footers
             Next oFooter
        Next oSection

For C#:

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Office.Interop.Word;

class Program
    static void Main(string[] args)
        List<string> path = new List<string>(args);

        string filePathstr = string.Join(" ", path.ToArray());
        //System.Windows.Forms.MessageBox.Show("filepathstr: " + filePathstr);

        string folderPathstr = Path.GetDirectoryName(filePathstr);
        //System.Windows.Forms.MessageBox.Show("folderPathstr: " + folderPathstr);

            Application ap = new Application();
            Document document = ap.Documents.Open(filePathstr);

            foreach (Section section in document.Sections)
                document.Fields.Update();  // update each section

                HeadersFooters headers = section.Headers;  //Get all headers
                foreach (HeaderFooter header in headers)
                    Fields fields = header.Range.Fields;
                    foreach (Field field in fields)
                        field.Update();  // update all fields in headers

                HeadersFooters footers = section.Footers;  //Get all footers
                foreach (HeaderFooter footer in footers)
                    Fields fields = footer.Range.Fields;
                    foreach (Field field in fields)
                        field.Update();  //update all fields in footers


        catch (NullReferenceException)
            System.Windows.Forms.MessageBox.Show("A valid file was not selected.");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.