Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • 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.
howto.JPG
0
avi666
Asked:
avi666
1 Solution
 
GrahamSkanRetiredCommented:
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
    Do
        oRange2.Fields.Update
        Set oRange2 = oRange2.NextStoryRange
    Loop Until oRange2 Is Nothing
Next oRange
End Sub

Open in new window

0
 
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)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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