Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jul 2003
    Location
    Burnaby, Br. Columbia, Canada
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Force a Save in Word (VBA for Word 2002)

    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Force a Save in Word (VBA for Word 2002)

    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.

  3. #3
    Lounger
    Join Date
    Jul 2003
    Location
    Burnaby, Br. Columbia, Canada
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force a Save in Word (VBA for Word 2002)

    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'! <img src=/S/blush.gif border=0 alt=blush width=15 height=15> Thanks for the tip...I'll give it a whirl.

    Cheers,
    Karina

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •