PDA

View Full Version : Solved: Update fields/links in header/footer Word 2007



evamads
12-15-2008, 10:39 AM
I have a document that has a header in it. In the header is this link/field:
{INCLUDETEXT "c:\Tilpas2007\Start\Brevhoved.docx" shs1}.

In Word 2003 I could use this code to update the field:
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader
Selection.WholeStory
Selection.Fields.Update

But in Word 2007 the field does not update, if it is placed in either a header or a footer. :wot

I have tried to record a macro going Office-button - Prepare - Edit Links to Files - Update

But this returns no VBA-code at all....

Can someone help?

Thanks,

/evamads

fumei
12-15-2008, 10:57 AM
I do not know about 2007, as I do not use it, but even for 2003, it would be better to use objects - rather than View, and Selection. It may work for 2007 as well.
Dim r As Range
Set r = ActiveDocument.Sections(1).Headers(2).Range

' 2 is wdHeaderFooterFirstPage

r.Fields.Update
Make a range object of the header (first page) and updates its fields. No need to go into View, or use Selection at all.

evamads
12-15-2008, 12:01 PM
It worked! :bow:

Thank You so much!!

/evamads

fumei
12-15-2008, 12:19 PM
You are welcome.

fumei
12-15-2008, 12:20 PM
Oh, if you are OK with things, could you please mark the thread as Solved? Use Thread tools at the top.

Thanks.