Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Automatically Update Cross Reference Field in Document Header

Posted on 2016-09-12
2
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

661 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