Solved

Automatically Update Cross Reference Field in Document Header

Posted on 2016-09-12
2
81 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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