Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Kamran Kamran is offline
external usenet poster
 
Posts: 80
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Kamran Kamran is offline
external usenet poster
 
Posts: 80
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How force FILENAME field code to update? Findor New Users 2 August 1st 07 10:32 AM
How to update ASK field code automatically when opening the doc? Paola Microsoft Word Help 1 January 3rd 06 10:54 AM
Date field code will not auto update MOTman Microsoft Word Help 1 June 18th 05 12:11 PM
How do I automatically update fields in a header/footer? Lee Ann Microsoft Word Help 2 May 24th 05 02:08 PM
Header - Sections - Update - Fields Francisco Microsoft Word Help 1 December 29th 04 03:50 PM


All times are GMT +1. The time now is 04:31 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"