• Update Field Codes (Word xp)

    Author
    Topic
    #388406

    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(wdHeaderFooterPrimary).Range.Fields.Update

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

    Viewing 1 reply thread
    Author
    Replies
    • #681758

      How about

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

      • #681762

        OK… I have it working … 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

    • #683865

      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…..

      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

      Hopefully this will help you get your fields updated.

    Viewing 1 reply thread
    Reply To: Update Field Codes (Word xp)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: