none
Word can not compare document error RRS feed

  • Question

  • Hi

    I am trying to compare two word document using CompareDocuments() VBA method. The issue is some time for some documents are having large no of pages , word is showing error message "Word cannot compare document". more details is :-

    1.This issue is coming randomly on some of the machines.

    2.This issue is coming only for large no of pages

    Could any one provide me the solution, as its urgently required.   

    Thursday, May 5, 2011 11:20 AM

Answers

  • Hi,

     

    I have edited your post to make the code more readable.

    I have several questions regarding the code above:

    1. You create a new document named worddoc3 as the result of CompareDocuments method. Why don’t you save this document but wrdDoc1?

    2. I notice that the CompareDocuments method is new method added in office 2007. So the code is based on Office 2007 or Office 2010, right?

    http://msdn.microsoft.com/en-us/library/bb256774(v=office.12).aspx

    http://msdn.microsoft.com/en-us/library/ff195665.aspx

     

    3. In Office 2003 and Office 2007, we use SaveAs method to save a document, but in Office 2010 there is some update. The method name changed to SaveAs2. See the document below:

    http://msdn.microsoft.com/en-us/library/aa220734(v=office.11).aspx

    http://msdn.microsoft.com/en-us/library/bb221597(v=office.12).aspx

    http://msdn.microsoft.com/en-us/library/ff836084.aspx

     

    So we can see that the code above will only work for Office 2007.

     

    Additionally, there are some small mistakes in the code. I have changed it as follow, which works fine in Office 2010:

     

    Sub DocumentCompare()
    
    Dim wrdApp As Word.Application
    Dim wrdDoc1 As Word.Document
    Dim wrdDoc2 As Word.Document
    Dim wrdDoc3 As Word.Document
    Set wrdApp = ActiveDocument.Application ' I haven't launched another word applicatoin
    
    Set wrdDoc1 = wrdApp.Documents.Open("D:\Test\Doc1.docx")
    Set wrdDoc2 = wrdApp.Documents.Open("D:\Test\Doc2.docx")
    
    Set wrdDoc3 = wrdApp.CompareDocuments(wrdDoc1, wrdDoc2, wdCompareDestinationNew, wdGranularityWordLevel, True, True, True, True, True, True, True, True, True, True, False)
    ChangeFileOpenDirectory "D:\Test\"
    
    wrdDoc3.SaveAs2 FileName:="Doc3.docx"
    wrdDoc1.Close
    wrdDoc2.Close
    
    End Sub
    

    I hope this helps


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 10, 2011 1:23 PM
    Moderator

All replies

  • Hi,

     

    I would like to know if the CompareDocuments() method is your custom method, as I haven’t found some similar methods except Document.Compare() method.

     

    If so, would you like to post the codes to let me know how the method performs?

     

    I look forward to hearing of you soon.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 9, 2011 11:37 AM
    Moderator
  • hi please find the code..
    Set wrdApp = CreateObject("Word.Application") 
    ' wrdApp.Visible = True
     Set wrdDoc1 = wrdApp.Documents.Open("D:\Automation\Temp\Doc1.doc") 
    Set wrdDoc2 = wrdApp.Documents.Open("D:\Automation\Temp\Doc2.doc") 
    Set worddoc3 = wrdApp.CompareDocuments(wrdDoc1,
     wrdDoc2, wdCompareDestinationNew, wdGranularityWordLevel, True, True, True, True, True, True, True, True, True, True, False) wrdDoc1.SaveAs "D:\Automation\Result\".doc" 
    wrdDoc2.Close 
    worddoc3.Close 
    wrdApp.Quit

    Hi
    Tuesday, May 10, 2011 5:31 AM
  • Hi,

     

    I have edited your post to make the code more readable.

    I have several questions regarding the code above:

    1. You create a new document named worddoc3 as the result of CompareDocuments method. Why don’t you save this document but wrdDoc1?

    2. I notice that the CompareDocuments method is new method added in office 2007. So the code is based on Office 2007 or Office 2010, right?

    http://msdn.microsoft.com/en-us/library/bb256774(v=office.12).aspx

    http://msdn.microsoft.com/en-us/library/ff195665.aspx

     

    3. In Office 2003 and Office 2007, we use SaveAs method to save a document, but in Office 2010 there is some update. The method name changed to SaveAs2. See the document below:

    http://msdn.microsoft.com/en-us/library/aa220734(v=office.11).aspx

    http://msdn.microsoft.com/en-us/library/bb221597(v=office.12).aspx

    http://msdn.microsoft.com/en-us/library/ff836084.aspx

     

    So we can see that the code above will only work for Office 2007.

     

    Additionally, there are some small mistakes in the code. I have changed it as follow, which works fine in Office 2010:

     

    Sub DocumentCompare()
    
    Dim wrdApp As Word.Application
    Dim wrdDoc1 As Word.Document
    Dim wrdDoc2 As Word.Document
    Dim wrdDoc3 As Word.Document
    Set wrdApp = ActiveDocument.Application ' I haven't launched another word applicatoin
    
    Set wrdDoc1 = wrdApp.Documents.Open("D:\Test\Doc1.docx")
    Set wrdDoc2 = wrdApp.Documents.Open("D:\Test\Doc2.docx")
    
    Set wrdDoc3 = wrdApp.CompareDocuments(wrdDoc1, wrdDoc2, wdCompareDestinationNew, wdGranularityWordLevel, True, True, True, True, True, True, True, True, True, True, False)
    ChangeFileOpenDirectory "D:\Test\"
    
    wrdDoc3.SaveAs2 FileName:="Doc3.docx"
    wrdDoc1.Close
    wrdDoc2.Close
    
    End Sub
    

    I hope this helps


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 10, 2011 1:23 PM
    Moderator
  • Hi

    Thanks for your help. 

    I used the code but it was not...working for me. Ans of you questions :-

    1. You create a new document named worddoc3 as the result of CompareDocuments method. Why don’t you save this document but wrdDoc1?

     

    Ans:- I tryied to save this document with name wrdDoc1 but it was giving me same error , Could you please let me know how saving wrdDoc1 will impact the method  CompareDocuments , if we are comparing two document manually using compare option its working fine but through code its not working.  

     

    2. I notice that the CompareDocuments method is new method added in office 2007. So the code is based on Office 2007 or Office 2010, right?

     

     

    Ans:- We have constaint , we can use only 2007 not 2010

     

    http://msdn.microsoft.com/en-us/library/bb256774(v=office.12).aspx

     

    http://msdn.microsoft.com/en-us/library/ff195665.aspx

     

     

     

    3. In Office 2003 and Office 2007, we use SaveAs method to save a document, but in Office 2010 there is some update. The method name changed to SaveAs2. See the document below:

     

    Ans :- We are not oging to use this method as we are using 2007

     

    http://msdn.microsoft.com/en-us/library/aa220734(v=office.11).aspx

     

    http://msdn.microsoft.com/en-us/library/bb221597(v=office.12).aspx

    http://msdn.microsoft.com/en-us/library/ff836084.aspx

     

    So the bottam line is while comparing two word document it should not through this error. Your help is apriciated .


    Hi
    Monday, May 16, 2011 5:49 AM