Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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.

share|improve this question
    
Do you know which line is causing the command failed message? I assume it's the Compare command, but I wanted to make sure. Then, is there anything interesting with the content with the docs that fail (embedded objects, etc.)? Finally, what happens if you try to compare the docs outside the script - i.e. using the Compare feature on the Review ribbon? –  Alan Jun 7 '11 at 20:00
    
The Compare line is what fails. The docs have form fields in them but the other docs we've compared also have form fields and we've not run into any problem. As for using the Compare feature, that's working just fine with either a Merge, Merge to New, Merge to same, or straight compare. That's why this is such a mystery, everything LOOKS like it should work... but it's not. And I have asked for help from the tool vendor and they have not been able to find anything (since, technically, it's not their tool causing the error). –  TristaanOgre Jun 7 '11 at 20:05
    
So you don't have to open the second document to compare the two? It opens the document for you when you call Compare()? You could try writing a VB.Net or C# console app and see if some exception details are returned... –  BrMcMullin Jun 7 '11 at 20:08
    
A little additional info... the Word documents are Word 2007 formatted docs. We've used the Word.Application object on both a machine with Word 2010 and Word 2003 installed without any change in behavior –  TristaanOgre Jun 7 '11 at 20:08
2  
@Bj - the compare function is part of the word object model - the vendor is MS :} –  Alan Jun 8 '11 at 16:38
show 10 more comments

2 Answers 2

up vote 7 down vote accepted

My transcribed debugging session is below - the short answer is that Compare will fail if there are unaccepted revision changes in the comparison document.

Details:

Here are some clues and potential answers.

  1. I reproduced the error
  2. I made a copy of the first doc and compared it with itself – that worked.
  3. I made a copy of the second file and compared it with itself – that reproduced the command failed error
  4. I tried comparing the docs from step3 (…observation.doc) manually from word. It worked, but I had to confirm that it was ok to compare against tracked changes
  5. Based on the above, I accepted all changes and saved the original doc, then reran the comparison – it worked!

So – it has something to do with the unaccepted changes to the doc.

My final experiment was to take a simple doc, turn on track changes, make some edits, then save without accepting. I compared this doc with itself and reproduced the error (command failed).

My advice: save the unaccepted changes before comparing (you can probably use Document.AcceptAllRevisions from the script if you want to).

share|improve this answer
    
+1 Bravo, @Alan! As I suspected, it was something that was simply an unexpected condition on the documents. The thing is, the revisions that are in the two docs are not visible, necessarily, and so opening up the documents did not expose them. –  TristaanOgre Jun 8 '11 at 20:30
    
+1 to Alan here, too. I've been having the same issue with very similar comparison code - now I know how to deal with it. Thank you! –  Kate Paulk Jun 9 '11 at 10:38
add comment

Created an automated appliction (.exe) to generate word document by using windows schedular we are calling the .exe file for every 1 hour.

while saving (saveas) throwing an error message "Command failed", if it is executed by using windows scheduler(selected even user logged off the system option).

Not throwing an error (creating the document successfully) by manually executing the .exe file.

share|improve this answer
    
Sree, this looks like you have a new question - you're more likely to have someone answer your question if you post it as a question. –  Kate Paulk Sep 26 '13 at 11:21
    
Welcome to SQA, Sree. I have to admit, I'm having trouble tying your answer to the question that was asked. If it is supposed to be an answer, you'll want to shore it up by bringing it into context. If it is indeed a new question, you should hit the "ask question" link at the top of this page, or right here: sqa.stackexchange.com/questions/ask –  corsiKa Sep 27 '13 at 9:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.