none
Macro to compare word documents and only produce output if discrepancy is found RRS feed

  • Question

  • Hello,

    I've created a macro where the user specifies two folders each of which contain versions of the same documents.  Then the macro compares each of the documents in one folder with its equivalent in the other folder.  Output is produced even if the two documents compared are identical.  My goal is to modify the macro so that an output comparison file is only produced if discrepancies are found between the two documents.  Any help on this would be greatly appreciated. 

    Here is the Macro I currently am working with:

    Sub CompareAllFiles()
      Dim strFolderA As String
      Dim strFolderB As String
      Dim strFolderC As String
      Dim strFileSpec As String
      Dim strFileName As String
      Dim objDocA As Word.Document
      Dim objDocB As Word.Document
      Dim objDocC As Word.Document
      strFolderA = InputBox("Enter path to base documents:")
      strFolderB = InputBox("Enter path to new documents:")
      strFolderC = InputBox("Enter path for document comparisons to be saved:")
      strFileSpec = "*.doc"
      strFileName = Dir(strFolderA & strFileSpec)
      Do While strFileName <> vbNullString
      Set objDocA = Documents.Open(strFolderA & strFileName)
      Set objDocB = Documents.Open(strFolderB & strFileName)
      Application.CompareDocuments _
      OriginalDocument:=objDocA, _
      RevisedDocument:=objDocB, _
      Destination:=wdCompareDestinationNew
      objDocA.Close
      objDocB.Close
      Set objDocC = ActiveDocument
      objDocC.SaveAs FileName:=strFolderC & strFileName
      objDocC.Close SaveChanges:=False
      strFileName = Dir
      Loop
    Set objDocA = Nothing
    Set objDocB = Nothing
    End Sub

    Thursday, March 1, 2012 1:07 PM

Answers

  • What I think you might be able to do is put in a revisions count check on objDocC and then take action based on the count.

        If obDdocC.Revisions.count = 0 Then
            objDocC.Close (wdDoNotSaveChanges)
        Else
            objDocC.SaveAs FileName:=strFolderC & strFileName
        End If


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by mpducincy Thursday, March 1, 2012 3:35 PM
    Thursday, March 1, 2012 2:37 PM

All replies

  • What I think you might be able to do is put in a revisions count check on objDocC and then take action based on the count.

        If obDdocC.Revisions.count = 0 Then
            objDocC.Close (wdDoNotSaveChanges)
        Else
            objDocC.SaveAs FileName:=strFolderC & strFileName
        End If


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by mpducincy Thursday, March 1, 2012 3:35 PM
    Thursday, March 1, 2012 2:37 PM
  • Works great.  Thanks.
    Thursday, March 1, 2012 3:35 PM
  • Works great. Thanks.
    Thursday, March 1, 2012 3:36 PM
  • I am sorry to be writing it here but I stumbled upon this post while trying to figure out an answer to my question and maybe you could help me out.

    In this table:

    postimg,org

    image

    yiiuv6lcv

    (dot instead of comma and / inbetween, http at the beginning. Sorry for this)

    You will see what I need. Imagine that the numbers 1-9 are words and the other numbers are percentages that show how similiar every document is to each other. I need exactly that: a method where I can input a number of word (combined with excel files would be great as well if possible) files and get a list of matches between all pairs of documents. Can this be done? Thanks a lot in advance!


    • Edited by Rainalkar Sunday, December 7, 2014 7:46 PM
    Sunday, December 7, 2014 7:45 PM
  • The thread you have added you post to is over 2 years old and it has nothing to do with your particular question.

    Please start a new question and make sure you provides all necessary information and URL links. More people, other than just me will then be able to help you. When you add onto a posting like this, many potential responders will ignore it because it is already an answered question.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, December 8, 2014 12:15 AM
  • I will. Thank you for the remark.
    Monday, December 8, 2014 5:22 PM