I need a macro to update the Header/footer areas

S

SandyB

I have created a template where certain fields from document properties need to be updated. Fields in the body of the document update fine but any fields in the header/footer area do not update. You have to open the hedaer/footer area and update each section separately. The only way I could do this was based on there always being a specific number of sections. What I really want is a macro that updates the header/footer area regardless of the number of sections

My existing macro is shown below..

Sub FooterUpdate(

' FooterUpdate Macro Updates footers in 3 Section
' Macro recorded 02/02/2004 by Sandy

Selection.HomeKey Unit:=wdStor
If ActiveWindow.View.SplitSpecial <> wdPaneNone The
ActiveWindow.Panes(2).Clos
End I
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow.
ActivePane.View.Type = wdOutlineView The
ActiveWindow.ActivePane.View.Type = wdPrintVie
End I
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeade
If Selection.HeaderFooter.IsHeader = True The
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFoote
Els
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeade
End I
Selection.WholeStor
Selection.Fields.Updat
ActiveWindow.ActivePane.View.NextHeaderFoote
Selection.WholeStor
Selection.Fields.Updat
ActiveWindow.ActivePane.View.NextHeaderFoote
Selection.WholeStor
Selection.Fields.Updat
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocumen
End Sub
 
C

Charles Kenyon

First, try Print Preview.

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview


Otherwise, ...

iCount = ActiveDocument.Sections.Count

will give you the number of sections and you can cycle through them. (You
can also cycle through without getting the count. However, I suspect that
Print Preview will take care of your problem.

If you need more help, write back in this thread including the version of
Word you are using.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

SandyB said:
I have created a template where certain fields from document properties
need to be updated. Fields in the body of the document update fine but any
fields in the header/footer area do not update. You have to open the
hedaer/footer area and update each section separately. The only way I could
do this was based on there always being a specific number of sections. What
I really want is a macro that updates the header/footer area regardless of
the number of sections.
 
J

Jezebel

You can update every field in a document regardless of location using code
like this:

Dim pRange as Word.Range
Dim pRange2 as Word.Range

For each pRange in ActiveDocument.StoryRanges
Set pRange2 = pRange
Do until pRange2 is nothing
pRange2.UpdateFields
Set pRange2 = pRange2.NextStoryRange
Loop
Next





SandyB said:
I have created a template where certain fields from document properties
need to be updated. Fields in the body of the document update fine but any
fields in the header/footer area do not update. You have to open the
hedaer/footer area and update each section separately. The only way I could
do this was based on there always being a specific number of sections. What
I really want is a macro that updates the header/footer area regardless of
the number of sections.
 
P

Peter Hewett

Hi ?Utf-8?B?U2FuZHlC?

Try the following code it will update all fields in your document:

Public Sub UpdateAllFields()
Dim lngJunk As Long
Dim rngStory As Word.Range

' Word missing first Header/Footer bug workaround
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType

' Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges

' Iterate through all linked stories
Do
' Do Update all fields
rngStory.Fields.Update

' Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
End Sub

It's more than the two lines Charles posted but it's quicker in practice.

HTH + Cheers - Peter
 
S

SandyB

Thanks for your reply. I didn't know enough to make it work but luckily Peter's reply filled in the gaps. I understood the principle but could not put it into practice
Cher
Sandy

----- Jezebel wrote: ----

You can update every field in a document regardless of location using cod
like this

Dim pRange as Word.Rang
Dim pRange2 as Word.Rang

For each pRange in ActiveDocument.StoryRange
Set pRange2 = pRang
Do until pRange2 is nothin
pRange2.UpdateField
Set pRange2 = pRange2.NextStoryRang
Loo
Nex





SandyB said:
I have created a template where certain fields from document propertie
need to be updated. Fields in the body of the document update fine but an
fields in the header/footer area do not update. You have to open th
hedaer/footer area and update each section separately. The only way I coul
do this was based on there always being a specific number of sections. Wha
I really want is a macro that updates the header/footer area regardless o
the number of sections
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top