Solved

Automatically Update Cross Reference Field in Document Header

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

738 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