Skip to content

Instantly share code, notes, and snippets.

@frogonwheels
Created September 30, 2011 01:10
Show Gist options
  • Save frogonwheels/1252396 to your computer and use it in GitHub Desktop.
Save frogonwheels/1252396 to your computer and use it in GitHub Desktop.
Compare word documents
' Created by: Michael Geddes
' Access to CLI Arguments
Set args = WScript.Arguments
if args.count = 0 then
ShowHelp
WScript.Quit 1
end if
' File System utilities
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Create a word application object.
Dim objword
' Create an object - events will be objword_*
set objword = Wscript.CreateObject("Word.Application","objword_")
' Full path of the two documents .. relative won't do.
Set doc1 = objword.Documents.Open(FullPath(args.Item(0)),,true)
Set doc2 = objword.Documents.Open(FullPath(args.Item(1)),,true)
' Compare the documents
Set DocComp = objword.CompareDocuments(doc1, doc2) ', wdCompareDestinationNew)
' Don't need these any more for some reason... it's already opened them again.
Doc1.Close
Doc2.Close
set doc1 = nothing
set Doc2 = nothing
' Make sure word is visible
objword.Visible = true
bquit = false
' Wait until word has finished.
do while not bquit
wscript.Sleep 1000
loop
set objword = nothing
' Event fired - we can stop now.
sub objword_quit
bquit = true
end sub
' Find the full path
function FullPath( pathname )
set ObjFile = objFSO.GetFile(pathname)
ret = objFSO.GetAbsolutePathName(objFile)
set ObjFile = nothing
FullPath = ret
end function
sub ShowHelp
WScript.echo "WordCompare.vbs {file1} {file2} - Compare two files in word"
end sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment