Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
UpdateAll fields code won't update header
Hello,
I want to use the code below to populate a header with info in Word form. There are two fields. In the second field I have selected the macro for "Run macro on Exit", but it doesn't work. The header fields stay unchanged. What am I missing? [From http://www.gmayor.com/installing_macro.htm] Sub UpdateAll() 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 |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
UpdateAll fields code won't update header
Hi Kamran,
Try adding the following lines to your code: Application.ScreenUpdating = False ActiveDocument.PrintPreview ActiveDocument.ClosePrintPreview Application.ScreenUpdating = True -- Cheers macropod [MVP - Microsoft Word] "Kamran" wrote in message ... Hello, I want to use the code below to populate a header with info in Word form. There are two fields. In the second field I have selected the macro for "Run macro on Exit", but it doesn't work. The header fields stay unchanged. What am I missing? [From http://www.gmayor.com/installing_macro.htm] Sub UpdateAll() 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 |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
UpdateAll fields code won't update header
I did away with the rest of the code and used what you provided and .....
SHAZAM! Sheer genius. Thanks for the help. |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
UpdateAll fields code won't update header
The macro should work with fields in the header - it does here, but headers
can be problematical. Use this code instead. Fields in the body of the form will be updated if you check the calculate on exit check box of the last relevant field. 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 -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Kamran wrote: Hello, I want to use the code below to populate a header with info in Word form. There are two fields. In the second field I have selected the macro for "Run macro on Exit", but it doesn't work. The header fields stay unchanged. What am I missing? [From http://www.gmayor.com/installing_macro.htm] Sub UpdateAll() 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How force FILENAME field code to update? | New Users | |||
How to update ASK field code automatically when opening the doc? | Microsoft Word Help | |||
Date field code will not auto update | Microsoft Word Help | |||
How do I automatically update fields in a header/footer? | Microsoft Word Help | |||
Header - Sections - Update - Fields | Microsoft Word Help |