Solved

Automatically Update Cross Reference Field in Document Header

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now