Solved

Automatically Update Cross Reference Field in Document Header

Posted on 2016-09-12
2
55 Views
Last Modified: 2016-09-12
I have several cross reference fields inserted into a Word document (2010).  I am using "Calculate on Exit" with the original form field to update the various cross reference fields throughout the document.  This is working fine for all cross reference EXCEPT those are are in my document header.  

Does anybody know of a way to automatically update cross reference fields in the header of a document?
0
Comment
Question by:nquinn94
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 41794910
I wasn't aware of that restriction, but it can be overcome with a VBA macro.

You should be aware that the text that you see in the presented document isn't in that sequence in the Word file. Some text can be 'called in' to show at different points. Headers and footers are a good example. In many documents there is only one header and one footer, so the text isn't repeated in the file. This saves storage space for repeated text.

Even if there are different headers and footers, they are still kept separately,

The different types of text are called StoryRanges and sometimes there are several StoryRanges of the same type, so to step through them all requires some code to step through each type and then to step through each instance of that type.

This macro will update the all the fields in the document, so make it the exit macro for some or all of the formfields

Sub UpdateAllStories()
    Dim myStoryRange As Range
    
    For Each myStoryRange In ActiveDocument.StoryRanges
        With myStoryRange
            .Fields.Update
        End With
        Do While Not (myStoryRange.NextStoryRange Is Nothing)
            Set myStoryRange = myStoryRange.NextStoryRange
            With myStoryRange
                .Fields.Update
            End With
        Loop
    Next myStoryRange
End Sub

Open in new window

0
 

Author Closing Comment

by:nquinn94
ID: 41794957
Works perfectly!  Thank you for your help!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question