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 / February 2005

Tip: Looking for answers? Try searching our database.

macro to update field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
raniet - 25 Feb 2005 05:31 GMT
How do I get automatically updated fields in the header?  I have a template
file that is large.  I would like the Heading 1 (i.e. Introduction, Chapter
1, etc.) to appear in the header.  I would like the header to automatically
update from a single macro instead of the recommended way of changing the
previous header manually.  I am also a novice when it comes to creating Word
Macros
G.G.Yagoda - 25 Feb 2005 05:52 GMT
The easiest way to update all fields in a document is to switch to the
Print Preview view then back.

   ActiveDocument.PrintPreview
   Selection.EscapeKey

Slightly crude, but it works.
Doug Robbins - 25 Feb 2005 10:30 GMT
To close Print Preview you can use

ActiveDocument.ClosePrintPreview

Of course using Print Preview will only work if the Update Fields option is
set under Tools>Options>Print.  If it is not, you will need to iterate
through all of the headers footers in the document using

Dim i as Long
For i = 1 to ActiveDocument.Sections.Count
   With ActiveDocument.Sections(i)
       .Headers(wdHeaderFooterFirstPage).Range.Fields.Update
       .Headers(wdHeaderFooterPrimary).Range.Fields.Update
       .Footers(wdHeaderFooterFirstPage).Range.Fields.Update
       .Footers(wdHeaderFooterPrimary).Range.Fields.Update
   End With
Next i

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> The easiest way to update all fields in a document is to switch to the
> Print Preview view then back.
[quoted text clipped - 3 lines]
>
> Slightly crude, but it works.
Charles Kenyon - 25 Feb 2005 16:24 GMT
Rather than use a macro, consider using the StyleRef field. In my experience
(at least in Word 2003) the StyleRef field is one of the few fields in Word
that seems to update automatically.

The following updates fields in headers and footers as well as in the main
doucment.

Private Sub FieldsUpdateAllStory()
'   All Story Field Updater
'   Written by Charles Kyle Kenyon 9 December 2004
'   repaired with help from Jezebel 10 December 2004
'   Note, if used in protected form this will reset
'       formfields to their defaults
   Dim oStory As Range
   On Error Resume Next
   For Each oStory In ActiveDocument.StoryRanges
       Do
           oStory.Fields.Update
           Set oStory = oStory.Next
       Loop Until oStory Is Nothing
   Next
End Sub
Signature


Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

> How do I get automatically updated fields in the header?  I have a
> template
[quoted text clipped - 6 lines]
> Word
> Macros

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.