Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

update fields in header

3 views
Skip to first unread message

lina

unread,
Nov 10, 2006, 8:31:49 AM11/10/06
to
Hi
I have at template that has variables in the header
I have a sub for updating all variables in headers but I have some troubles
with update the variables in the first page header that is set to different
fist page. I have tryed different solutions for this but none of them seems
to work 100 % corrrect because some times the first page header does not
update. Not even if I use the code
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

If I manually set the document to pritnpriview and back the variable
updates.
Has anyone have had the same problem or a solution to the problem?
Thanks

Thanks

Graham Mayor

unread,
Nov 10, 2006, 8:36:03 AM11/10/06
to
Try the following:

Sub UpdateHeaderFooter()
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
oField.Update
Next oField
End If
Next oFooter
Next oSection
End Sub

or


Sub UpdateAllFields()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org

lina

unread,
Nov 10, 2006, 9:48:31 AM11/10/06
to
Thanks it works fine now

"Graham Mayor" <gma...@REMOVETHISmvps.org> skrev i meddelandet
news:O$gls0MBH...@TK2MSFTNGP03.phx.gbl...

0 new messages