How To: Update all headers & footers when fields are changed?

B

Barry

I am trying to create a Word'03 template that includes a few form text fields
that I want to populate the header and footer of the document, and change
when the user changes the text in those fields.
I have done this for one section, the first section is the first page and
never displays the header/footer, but users can create new sections
throughout the document.
Code is called on exit from the form fields and looks like this:

Sub updateHeaderFooterFields()
With ActiveDocument.Sections(2)
.Headers(wdHeaderFooterPrimary).Range.Fields.Update
.Footers(wdHeaderFooterPrimary).Range.Fields.Update
End With
End Sub

So, how do I update al headers/footers in all sections?
Thx,
Barry
 
D

Doug Robbins - Word MVP

The "quick and dirty" way is to use

With ActiveDocument
.PrintPreview
.ClosePrintPreview
End With

Alternatively

Sub updateHeaderFooterFields()

Dim i as Long
With ActiveDocument
For i = 1 to .Sections.Count
With .Sections(i)
.Headers(wdHeaderFooterPrimary).Range.Fields.Update
.Footers(wdHeaderFooterPrimary).Range.Fields.Update
End With
Next i
End With
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Barry

Thx Doug,
I didn't go with the Quick n Dirty solution.
A year from now I wouldn't remember why I did it that way.
The full-on solution works flawlessly though...
Thx,
Barry
 
V

Victorhall

Thanks - the quick and dirty worked great for me - no idea why, but it did.
I tried the second way, and couldn't get it to work.
-Vic
 

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