I have two word documents that are a "result" of a test and an "expected result". I'm using the following code to compare the two and check for differences.
Sub CompareTest Dim wrdApp Dim revTemp Dim file1, file2, differences Set wrdApp = Sys.OleObject("Word.Application") file1 = "C:\TestDocs\Site Initiation.doc" file2 = "C:\TestDocs\Site Initiation_observer.doc" differences = "C:\TestDocs\differences.doc" call wrdApp.Documents.Open(file1) call wrdApp.ActiveDocument.Compare(file2, "", 1) Set revTemp = wrdApp.Selection.NextRevision(True) If Not (revTemp Is Nothing) Then wrdApp.ActiveDocument.SaveAs differences wrdApp.Documents.Close Call Log.Warning "Documents are not identical", "Please see the differences in " & differences Else Call Log.Message "Documents are identical" End If wrdApp.Quit False End Sub
For whatever reason, for most of the word documents we're comparing like this, everything works fine. However, for two of them we're comparing, we're getting "Command Failed" on the line that is calling the "Compare" method.
I've searched Microsoft's library on line, numerous blogs, etc., and no one can give me a specific situation where this code would work for MOST documents but not for certain scenarios. I've tried reversing the order of the documents, changing the document names and the directory paths to be more compatible with an 8.3 format. I've tried comparing each document to itself as well.
A little help would be greatly appreciated.
FYI, this is code being run in the TestComplete automated testing tool so the specifics of "Sys.OleObject" and the "Log" object are internal to that tool. We've used "CreateObject" and commented out the Log calls to no avail.