ActiveDocument.Compare function RRS feed

  • Question

  • I'm not familiar with the 'compare' function in word 2010.  Have created a macro to 'unlock read-only form' (compare not available with cursor in editable area and form locked)... then I want to activate the Compare feature for the user.  Have

    Sub CompareDocs()

    If ActiveDocument.ProtectionType <> wdNoProtection Then
        ActiveDocument.Unprotect Password:="password"
           MsgBox "Compare Documents"
           ActiveDocument.Compare Name:=<Previous Version>  (Here unfortunately, I'm clueless)
        MsgBox "Ready to Compare Documents"
    End If

    End Sub

    Getting error messages and don't know at this point what needs to be changed/added...

    Can someone explain how 'compare' needs to be written?  Also - once Compare has been initiated and the the user finishes the process.  Is the starting document exited.  Does the user need to save the document prior to comparing?  Obviously - there's a lot to learn!

    Regards - Lenny33

    Friday, August 2, 2013 5:02 PM


  • Hi Lenny33,

    Document.Copare method will display revision marks that indicate where the specified document differs from another document.

    Below is a simple example:

    Sub CompareDocument()
    ActiveDocument.Compare Name:=" C:\Drafts\PreVersion.docx", CompareTarget:=wdCompareTargetCurrent
    End Sub

    You can place comparison differences in different document through CompareTarget parameter:

    • wdCompareTargetCurrent: Places comparison differences in the current document. Default.
    • wdCompareTargetNew: Places comparison differences in a new document.
    • wdCompareTargetSelected: Places comparison differences in the target document.

    Jeffrey Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, August 3, 2013 8:05 AM