Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating Footer Fields with Code (Word97)

    Why does the ActiveDocument.Fields.Update command in Word97 not update fields in the header or footer?

    I need to update fields in my header and footer with code - how can I automate this?

    Thanks for your help.

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Updating Footer Fields with Code (Word97)

    It doesn't do it because the footers are not part of the ActiveDocument story.

    You will find the code to do this back in the archives in messages such as this Updating all fields in all storyTypes

    You could also do it by moving from Normal View to Page Layout view.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating Footer Fields with Code (Word97)

    Here is a macro that will do what you want.

    The only thing (IIRC) that it won't do is update any fields in
    Textboxes. That is something I have been meaning to add, when I
    have time.

    <pre>Sub sUpdateFields()
    '---------------------------------------------------------------------------------------
    ' Procedure : sUpdateFields
    ' DateTime : 12-Dec-2001
    'Author : Bryan Carbonnell
    ' Purpose : To update all fields in the Word Doucument
    ' including TOC, TOA, TOF and Fields in Headers/Footers
    '---------------------------------------------------------------------------------------


    Dim doc As Document ' Pointer to Active Document
    Dim wnd As Window ' Pointer to Document's Window
    Dim lngMain As Long ' Main Pane Type Holder
    Dim lngSplit As Long ' Split Type Holder
    Dim lngActPane As Long ' ActivePane Number
    Dim rngStory As Range ' Range Objwct for Looping through Stories
    Dim TOC As TableOfContents ' Table of Contents Object
    Dim TOA As TableOfAuthorities 'Table of Authorities Object
    Dim TOF As TableOfFigures 'Table of Figures Object

    ' Set Objects
    Set doc = ActiveDocument
    Set wnd = ActiveDocument.ActiveWindow
    ' get Active Pane Number
    lngActPane = wnd.ActivePane.Index
    ' Hold View Type of Main pane
    lngMain = wnd.Panes(1).View.Type
    ' Hold SplitSpecial
    lngSplit = wnd.View.SplitSpecial
    ' Get Rid of any split
    wnd.View.SplitSpecial = wdPaneNone
    ' Set View to Normal
    wnd.View.Type = wdNormalView

    ' Loop through each story in doc to update
    For Each rngStory In doc.StoryRanges
    If rngStory.StoryType = wdCommentsStory Then
    Application.DisplayAlerts = wdAlertsNone
    ' Update fields
    rngStory.Fields.Update
    Application.DisplayAlerts = wdAlertsAll
    Else
    ' Update fields
    rngStory.Fields.Update
    End If
    Next

    ' Loop through TOC and update
    For Each TOC In doc.TablesOfContents
    TOC.Update
    Next

    ' Loop through TOA and update
    For Each TOA In doc.TablesOfAuthorities
    TOA.Update
    Next

    ' Loop through TOF and update
    For Each TOF In doc.TablesOfFigures
    TOF.Update
    Next

    ' Return Split to original state
    wnd.View.SplitSpecial = lngSplit
    ' Return main pane to original state
    wnd.Panes(1).View.Type = lngMain
    ' Active proper pane
    wnd.Panes(lngActPane).Activate
    ' Close and release all pointers
    Set wnd = Nothing
    Set doc = Nothing

    End Sub
    </pre>


    This updates all fields including in the header/footers TOC, TOA
    and TOFs

    You can then assign this macro to the F9 key if you wish, or any
    other key combo you want.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  4. #4
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating Footer Fields with Code (Word97)

    Its not very 'learned' but I just switch to printview and back again.

    ActiveDocument.PrintPreview
    ActiveDocument.ClosePrintPreview

    I find that this takes a lot less code and allows me to use doc properties to update my header/footers.

Posting Permissions

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