Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Aug 2002
    Location
    Sierra Madre, California, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA code for updating footer fields (Word 2000/XP)

    I need a way to update fields in a footer. I have a create date field and a file path field. The problem I have is that when the file name is changed (i.e. saving a copy with a diff file name - this is for legal blacklining) the field in the footer is not updated.

    Microsoft's solution is to turn on "update fields on print" under Options; however, I cannot use this because it tries to update ALL the fields in the document. I need to figure out some way to update ALL of the footers (regardless of how many sections I have).

    I would like to create a VBA-based button to use or a way of having it do it automatically. Any suggestions? What I'm using now is:

    Sub FooterUpdate()
    Selection.HomeKey Unit:=wdStory

    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    ActiveWindow.Panes(2).Close
    End If

    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    ActivePane.View.Type = wdOutlineView Then
    ActiveWindow.ActivePane.View.Type = wdPrintView
    End If

    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Selection.WholeStory
    Selection.Fields.Update

    ActiveWindow.ActivePane.View.NextHeaderFooter
    Selection.WholeStory
    Selection.Fields.Update

    'I thought I could just repeat these lines a couple of times - any way to make it loop for the number of sections in the document?

    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End Sub

    Thanks,
    Kris

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: VBA code for updating footer fields (Word 2000/XP)

    Kris,

    Here's a very efficient way to do it - note that this does not require actually 'visiting' each footer with Selection:

    <pre>Public Sub UpdateFooterFields()
    Dim oSection As Section
    Dim oFooter As HeaderFooter
    For Each oSection In ActiveDocument.Sections
    For Each oFooter In oSection.Footers
    If Not oFooter.LinkToPrevious Then oFooter.Range.Fields.Update
    Next 'oFooter
    Next 'oSection
    End Sub
    </pre>

    (tip of cap to Stuart R.)
    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •