none
How to Identify whether the Word document has undergone any changes? (Without using Tracking or without enabling Track Changes) RRS feed

  • Question

  • Need help! I would like to Identify whether the Word document has modified since the time it has been opened till before closing. While closing the word document, a Boolean value should be returned based on either the document undergone changes or no changes made to the document since opened. I want this to be achieved using word VBA code or using Java Script.

    Document.Saved Property doesn't fulfill my requirement since it will help us knowing only the unsaved changes if any whereas my requirement is to identify the changes regardless to either the document is saved or not.

    Thanks in advance.

    Friday, July 11, 2014 2:06 PM

All replies

  • Given the restriction you put in the subject line, as well as the one in the text, no, what you ask is not possible. Unless you were to make a copy of the original document before it has been edited and compare it with the document that has been closed.

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 11, 2014 3:31 PM
    Moderator
  • First of all thank you for your time.

    Kindly check the code below which I have tried to compare two word documents. Its working fine, its comparing the given two word documents and giving a new third document in which the result content is created, what I am expecting is someone’s help to have a flag set in this module and it should be returned as either true or false based on whether the destination document undergone changes or no changes done to the original document respectively.

    The challenge i am facing here is, while comparing two word documents which are similar but then i am getting the third resultant word document with same as the destination word document.

    Is there any property or parameter which will tell us the number of changes made to the original document.

    Any kind of help is much appreciated.

    Here is the code for your reference:

    [Code]

    Sub Compare2Documents()

        Original_Document = "C:\Users\rajeshb\Desktop\SampleDraft1.docx"

        Revised_Document = "C:\Users\rajeshb\Desktop\SampleDraft2.docx"

        Original_Document = "SampleDraft1.docx"

        Revised_Document = "SampleDraft2.docx"

        Application.CompareDocuments OriginalDocument:=Documents( _

            Original_Document), RevisedDocument:=Documents(Original_Document), _

            Destination:=wdCompareDestinationNew, Granularity:=wdGranularityWordLevel _

            , CompareFormatting:=True, CompareCaseChanges:=True, CompareWhitespace:= _

            True, compareTables:=True, CompareHeaders:=True, CompareFootnotes:=True, _

            CompareTextboxes:=True, CompareFields:=True, CompareComments:=True, _

            CompareMoves:=True, RevisedAuthor:="", _

            IgnoreAllComparisonWarnings:=False

        ActiveWindow.ShowSourceDocuments = wdShowSourceDocumentsBoth

    End Sub

    [/Code]

     

    Thanks in advance.

    Friday, July 11, 2014 4:34 PM
  • HI Rajesh

    I'm not sure I understand your problem... The Help for CompareDocuments states:

    "Compares two documents and returns a Document object that represents the document that contains the differences between the two documents, marked using tracked changes."

    This means you can:

    Dim resultDoc as Word.Document = Application.CompareDocuments 'More follows here

    Which gives you a way to work with the result containing the tracked changes / comparison directly.

    <<Is there any property or parameter which will tell us the number of changes made to the original document.>>

    The changes are in the Revisions object. Does that help?


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 11, 2014 5:02 PM
    Moderator
  • Cross-posted (and answered before posting here) at: http://www.msofficeforums.com/word-vba/21785-how-identify-whether-word-document-has-undergone.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, July 12, 2014 2:53 AM
  • Hi Paul

    I don't see that the OP received the answer he's looking for in the discussion to which you link? Also not in the link in that discussion...


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, July 12, 2014 8:08 PM
    Moderator
  • The advice given there, especially as per the link, is essentially the same as what you subsequently advised on Friday, July 11, 2014. The fact the OP doesn't like the advice doesn't make it any less an answer.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Sunday, July 13, 2014 1:44 PM
  • HI Paul

    Maybe I missed it, but I don't find reference to the Revisions object in that link...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, July 14, 2014 1:56 PM
    Moderator
  • As the subject line says: "Without using Tracking or without enabling Track Changes". Using the Revisions object in the open document necessitates the use of change tracking...

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, July 15, 2014 2:56 AM
  • not if he's using Compare, which is apparently acceptable, probably because it's another document...

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 15, 2014 4:11 AM
    Moderator