none
How to check if word document has changes

    Question

  • I'm creating a VSTO Word Add-in and using Microsoft.Office.Interop.Word version 12 (Office 2007).

    How do I check if the open word document has changes not saved?

    Thanks
    Wednesday, August 13, 2008 2:09 PM

Answers

  • Hi Paulo

     

     Paulo Gonçalves wrote:
    I'm creating a VSTO Word Add-in and using Microsoft.Office.Interop.Word version 12 (Office 2007).

    How do I check if the open word document has changes not saved?

     

    The Document object has a Saved property. If that is true, there are no changes to be saved:

     

    If oDoc.Saved <> true Then

    'Save the document

    odoc.Save

    End If

     

    Please note that a document may be "dirty" (contain unsaved changes) even though the user has done nothing at all other than open it. This would be the case, for example, if the document contains a Date field that has updated.

    Thursday, August 14, 2008 8:37 AM

All replies

  • may be this is helpful..

     

    using ComTypes = System.Runtime.InteropServices.ComTypes;

     

    ComTypes.IPersistFile persistFile = (ComTypes.IPersistFile)documnet;

    //Checks an object for changes since it was last saved to its current file.

    if (persistFile.IsDirty)

    {

    //do your stuff

    }

    Wednesday, August 13, 2008 9:50 PM
  • Hi Paulo

     

     Paulo Gonçalves wrote:
    I'm creating a VSTO Word Add-in and using Microsoft.Office.Interop.Word version 12 (Office 2007).

    How do I check if the open word document has changes not saved?

     

    The Document object has a Saved property. If that is true, there are no changes to be saved:

     

    If oDoc.Saved <> true Then

    'Save the document

    odoc.Save

    End If

     

    Please note that a document may be "dirty" (contain unsaved changes) even though the user has done nothing at all other than open it. This would be the case, for example, if the document contains a Date field that has updated.

    Thursday, August 14, 2008 8:37 AM
  • Thanks,
    It's working fine.

    I was looking for a property like Document.HasChanges... Document.Saved is ok.
    I have some difficulty to find the correct documentation and exemples for the interops that I'm using, for office 2007.

    Thursday, August 14, 2008 11:23 AM
  • Hello,

     

    I'm using DSOFramer to embed Word 2007 in a WinForms application, is there an event in the DocumentClass (or an other way) to get notified when the word document is dirtied?

     

    Thanks

     

    Wednesday, August 27, 2008 10:06 AM