Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Update Field Codes (Word xp)

    I have a template that I created a userform to update a DocVariable field. [HANSV, I used your sample that you offered in another thread]. But I can't seem to get the variable in the footer to update.

    This is to update the header: ActiveDocument.Sections(1).Headers(wdHeaderFooterP rimary).Range.Fields.Update

    But I can't figure out how to update the footer.
    -jody

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Update Field Codes (Word xp)

    How about

    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Fields.Update

  3. #3
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Update Field Codes (Word xp)

    OK... I have it working [img]/forums/images/smilies/smile.gif[/img]... thanks...

    I had tried that... and it didn't work for me... The real problem was that I needed to change it to section 2 (my cover has different Head/Footers)

    Cheers - J

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

    Re: Update Field Codes (Word xp)

    Just catching up after being away.

    Here is a procedure that will update all fields in a Word document, regardless of where they are, headers, footers, text boxes, main body.....

    <pre>Public Sub UpdateAllFields()
    '---------------------------------------------------------------------------------------
    ' Procedure: sUpdateFields (V2)
    ' DateTime : 20-Dec-2001
    ' Updated : 06-Nov-2002 - Update fields in Text Boxes
    ' Author : Bryan Carbonnell
    ' With code by Nancy Hutson Hale
    ' Purpose : To update all fields in the Word Document including TOC, TOA, TOF,
    ' fields in text boxes 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 Object 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
    Dim shp As Shape 'Shape Object to get Textboxes

    ' 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 text boxes and update
    ' added by Nancy Hutson Hale - Nov 6, 2002
    For Each shp In doc.Shapes
    With shp.TextFrame
    If .HasText Then
    .TextRange.Fields.Update
    End If
    End With
    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>

    Hopefully this will help you get your fields updated.
    --
    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

  5. #5
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Update Field Codes (Word xp)

    THANKS!

Posting Permissions

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