Group:  Microsoft Word ยป microsoft.public.word.vba.beginners
Thread: How To: Update all headers & footers when fields are changed?

Geek News

How To: Update all headers & footers when fields are changed?
Barry 10/28/2008 8:36:05 PM
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
Re: How To: Update all headers & footers when fields are changed?
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 10/28/2008 10:18:40 PM
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

"Barry" <Barry[ at ]discussions.microsoft.com> wrote in message
news:18B2AE76-6BF4-4618-A763-DF9E50EF6FCA[ at ]microsoft.com...
[Quoted Text]
>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


Re: How To: Update all headers & footers when fields are changed?
Barry 10/28/2008 10:53:01 PM
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

"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> 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
>
> "Barry" <Barry[ at ]discussions.microsoft.com> wrote in message
> news:18B2AE76-6BF4-4618-A763-DF9E50EF6FCA[ at ]microsoft.com...
> >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
>
>
>
Re: How To: Update all headers & footers when fields are changed?
Victorhall 12/29/2008 9:02:01 PM
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

"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> The "quick and dirty" way is to use
>
> With ActiveDocument
> .PrintPreview
> .ClosePrintPreview
> End With

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net