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

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

Updating fields in a Word Document VBA code

I have a piece of code that opens a Word Document prints it then closes it.

        Set WordObj = CreateObject("Word.Application")
        WordObj.Documents.Open bob
        WordObj.PrintOut Background:=False
        WordObj.Quit False
        Set WordObj = Nothing

There is a date field that is embedded in the document. When the Document prints it does not update the date field. The inetersting thing is that when the user that  c reated the document prints the document the field gets updated but when anyone else runs the code it does not update the field.

Thanx in advance
1 Solution
What sort of date field is it?

This should update all fields in the document.

    Dim Doc As Word.Document
    Dim sty As Word.Range
    Set WordObj = CreateObject("Word.Application")
    Set Doc = WordObj.Documents.Open(bob)
    For Each sty In Doc.StoryRanges
        sty.Fields.Update False
    Next sty
    WordObj.PrintOut Background:=False
    WordObj.Quit False
    Set WordObj = Nothing

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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