Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

update fields in header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lina - 10 Nov 2006 13:31 GMT
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 - 10 Nov 2006 13:36 GMT
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

Signature

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

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

> Hi
> I have at template that has variables in the header
[quoted text clipped - 12 lines]
>
> Thanks
lina - 10 Nov 2006 14:48 GMT
Thanks it works fine now

> Try the following:
>
[quoted text clipped - 53 lines]
>>
>> Thanks

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.