• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

updating fields in word using vb

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

avi666Author Commented:
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)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now