[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [TSVN] VBScript for comparing two MS Word documents

From: Rainer Müller <mueller_rainer_at_gmx.de>
Date: 2005-07-08 20:01:04 CEST

Mark Phippard wrote:
> I have attached a new version that has a bit more polish. It does a
> bunch of error checks and gives appropriate error messages. I will
> see if I can do a Merge version now.

Tested and works with Word 2002 SP3 (10.6612.6735) - also known as Word XP.

I just looked at the code and changed a few things to improve it a bit more.

1) I moved the
        Word.Visible = True
   to the end of the script because otherwise you get one Word window
   shortly flashing.

2) Added
        On Error Goto 0
   otherwise no errors would get reported after the On Error Resume Next

I added the full script as an attachment.

Nice work, Mark! It is really a good thing to have.

Rainer

option explicit

dim objArgs,num,sBaseDoc,sNewDoc,objScript,word,destination

Set objArgs = WScript.Arguments
num = objArgs.Count
if num < 2 then
   MsgBox "Usage: [CScript | WScript] compare.vbs base.doc new.doc", vbExclamation, "Invalid arguments"
   WScript.Quit 1
end if

sBaseDoc=objArgs(0)
sNewDoc=objArgs(1)

Set objScript = CreateObject("Scripting.FileSystemObject")
If objScript.FileExists(sBaseDoc) = False Then
    MsgBox "File " + sBaseDoc +" does not exist. Cannot compare the documents.", vbExclamation, "File not found"
    Wscript.Quit 1
End If
If objScript.FileExists(sNewDoc) = False Then
    MsgBox "File " + sNewDoc +" does not exist. Cannot compare the documents.", vbExclamation, "File not found"
    Wscript.Quit 1
End If

Set objScript = Nothing

On Error Resume Next
set word = createobject("Word.Application")
If Err.Number <> 0 Then
   Wscript.Echo "You must have Microsoft Word installed to perform this operation."
   Wscript.Quit 1
End If

On Error Goto 0

' Open the new document
set destination = word.Documents.Open(sNewDoc)
' Hide it
destination.Windows(1).Visible=0
    
' Compare to the base document
destination.Compare(sBaseDoc)
    
' Show the comparison result
word.ActiveDocument.Windows(1).Visible = 1
    
' Mark the comparison document as saved to prevent the annoying
' "Save as" dialog from appearing.
word.ActiveDocument.Saved = 1
    
' Close the first document
destination.Close

word.visible=True

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Fri Jul 8 20:02:10 2005

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.