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

Tip: Looking for answers? Try searching our database.

AutoOpen Footer Updates

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tywardreath - 08 Sep 2005 04:50 GMT
Hi

I have a template that is set up with headers/footers, different first page.
I use the following macro to update the filename field within the footer/s.

Sub AutoOpen()
   Dim oField As Word.Field
   Dim oRange As Word.Range
   Set oRange = ActiveDocument.Sections(1).Footers(2).Range
   
   If oRange.Fields.Count >= 1 Then
       For Each oField In oRange.Fields
           If oField.Type = wdFieldFileName Then
               oField.Update
           End If
       Next
   End If
End Sub

My problem is that it only updates the filename on the first page. Is there
anyway to change the code so it updates it on the 2nd and subsequent pages?

Cheers, Ty
Tywardreath - 08 Sep 2005 05:30 GMT
I've been trying to use something with:
   ActiveDocument.StoryRanges(wdPrimaryFooterStory).Fields.Update
   ActiveDocument.StoryRanges(wdFirstPageFooterStory).Fields.Update

but I get unstuck if the document that is being opened doesn't have footers
different first page. I'm quite perplexed now :(

I'd like to use the same code for AutoOpen and AutoNew.

Cheers, Ty
Tywardreath - 08 Sep 2005 06:00 GMT
I've found the following code, which seems to work. The only problem is that
it doesn't work when Word is initialy opened. Any ideas?

Sub AutoNew()
Dim Story As Variant
Dim rngNext As Word.Range

' Iterate through all story types
For Each Story In ActiveDocument.StoryRanges

' Only update fields in a footer
If Story.StoryType = wdPrimaryFooterStory Or _
Story.StoryType = wdFirstPageFooterStory Or _
Story.StoryType = wdEvenPagesFooterStory Then

' Update fields in this footer
Story.Fields.Update

' There may be linked footers so update them as well
Set rngNext = Story.NextStoryRange
Do Until rngNext Is Nothing

' Update fields in this footer
rngNext.Fields.Update

' Link to next story (if any)
Set rngNext = rngNext.NextStoryRange
Loop
End If
Next
End Sub
Chuck Henrich - 08 Sep 2005 11:28 GMT
The following code is a bit simpler.  It goes through every footer in every
section, and updates the fields.  

Dim ftrFooter As HeaderFooter
Dim x As Long

With ActiveDocument

   For x = 1 To .Sections.Count
       For Each ftrFooter In .Sections(x).Footers
           ftrFooter.Range.Fields.Update
       Next ftrFooter
   Next x

End With

I've tested it in an AutoNew macro and it seems to work fine.
Signature

Chuck Henrich
www.ProductivityApps.com

> I've found the following code, which seems to work. The only problem is that
> it doesn't work when Word is initialy opened. Any ideas?
[quoted text clipped - 27 lines]
> Next
> End Sub
 
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.