updating fields in word using vb

Posted on 2009-02-15
Last Modified: 2012-05-06
hi experts.
took me a while to understand how to update fields in word document. found out  "ActiveDocument.Fields.Update" command but I had a field in the header that was not updated with this command

so I found the "ActiveDocument.Sections(1).Headers(1).Range.Fields.Update" and was happy but once again, I had a field inside a shape that wasn't updated by both commands.

so I wonder, what are all the options to update a CustomDocumentProperty in a document, no matter where its location? what collections should I check? (Sections? StoryRanges? Shapes?)

I'm lost.
Question by:avi666
    LVL 76

    Accepted Solution

    To be certain, you have to process each range in each story.
    Private Sub UpdateAllFields()
    Dim oRange As Range
    Dim oRange2 As Range
    ' Go through all story ranges in the document, including shapes,
    ' headers & footers.
    For Each oRange In ActiveDocument.StoryRanges
        Set oRange2 = oRange 'set oRange2 to first range in story
            Set oRange2 = oRange2.NextStoryRange
        Loop Until oRange2 Is Nothing
    Next oRange
    End Sub

    Open in new window


    Author Closing Comment

    easy. fast. working. thank you.

    (though I wish I knew more about Word architecture and how to get to fields directly and not through all-around loops)

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
    There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
    This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
    The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now