• Force a Save in Word (VBA for Word 2002)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Force a Save in Word (VBA for Word 2002)

    Author
    Topic
    #405828

    I have found as a user of Word that there are some things that you can do in a document that Word does not consider a ‘change’ and therefore, even when you do a File, Save, it doesn’t Save…unless you do something that it thinks is a ‘change’ and dirty the document (like pressing the spacebar and deleting it), then when you do a File, Save it actually will save the doc.

    Well, now, programming I have encountered the same thing. My code has to ensure the user has saved the document prior to running (because the code is pushing the document to a web service and the file must be saved). At any rate, we get the user to save the document prior to allowing the code to run, then we post the document to the web service. This all works just fine. However, I then create a custom document property in the document and assign it either true or false to indicate whether the post was successful or not. Because the only new thing in the document since being saved is the creation of a doc property, Word doesn’t think the document contains any changes, and when I do ActiveDocument.Save, it doesn’t save. I have tried manually creating the custom doc prop, and Word does think that is a change, and will save it, but not when I do it with code. I have tested this in other documents with other code and found the same thing.

    So, I am wondering if anyone knows of a way other than ActiveDocument.Save to force Word to save a document. I could of course just dirty the document by inserting a space and removing it, or some such thing, but I would rather not if there is a better alternative.

    Viewing 1 reply thread
    Author
    Replies
    • #836767

      Word keeps track of whether a document has changed since the last save in the Saved property: if Saved is True, the document has not changed, but if Saved is False, it has. So you can trick Word into thinking the document has changed by setting

      ActiveDocument.Saved = False

      If you then call

      ActiveDocument.Save

      it will actually be saved again.

      • #836909

        Hi Hans, stupid me, I never thought of that, even though I used the command to check to see if Word considered my new custom doc prop to be a ‘change’! blush Thanks for the tip…I’ll give it a whirl.

        Cheers,
        Karina

      • #836910

        Hi Hans, stupid me, I never thought of that, even though I used the command to check to see if Word considered my new custom doc prop to be a ‘change’! blush Thanks for the tip…I’ll give it a whirl.

        Cheers,
        Karina

    • #836768

      Word keeps track of whether a document has changed since the last save in the Saved property: if Saved is True, the document has not changed, but if Saved is False, it has. So you can trick Word into thinking the document has changed by setting

      ActiveDocument.Saved = False

      If you then call

      ActiveDocument.Save

      it will actually be saved again.

    Viewing 1 reply thread
    Reply To: Force a Save in Word (VBA for Word 2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: