Updating fields in a Word Document VBA code

Posted on 2006-05-25
Last Modified: 2006-11-18
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
Question by:Idarac
    1 Comment
    LVL 76

    Accepted 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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
    Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
    This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now