Hello,
I have extended the Excel diff script (.vbs) that was created by Suraj Barkale. In the new version the cells in the first worksheet of workbook 1, that are different to the cells in the first worksheet of workbook 2, are marked in red. Therefore it is much easier to find the differences in the side-by-side view. I have tested the script in Excel 2003 and it works fine. I use conditional formatting to mark the cells that are different. This method is very fast (I tested several ways). The script also works with two Excel workbooks that are dragged&dropped to the script's icon in the Windows Explorer. I hope you enjoy it!
Stefan Cytrynski
Stuttgart, Germany
-------------------------------------------------------------------------------------------------------
dim objExcelApp, objArgs, objScript, objBaseDoc, objNewDoc
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 = CreatexObject("Scripting.FileSystemxObject")
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 objExcelApp = Wscript.CreatexObject("Excel.Application")
If Err.Number <> 0 Then
Wscript.Echo "You must have Excel installed to perform this operation."
Wscript.Quit 1
End If
'Open base excel sheet
objExcelApp.Workbooks.Open sBaseDoc
'Open new excel sheet
objExcelApp.Workbooks.Open sNewDoc
'Show Excel window
objExcelApp.Visible = True
'Create a compare side by side view
objExcelApp.Windows.CompareSideBySideWith(objExcelApp.Windows(2).Caption)
If Err.Number <> 0 Then
objExcelApp.DisplayAlerts = False
objExcelApp.Quit()
Wscript.Echo "You must have Excel 2003 or later installed to use compare side-by-side feature."
Wscript.Quit 1
End If
'Mark differences in sNewDoc red
objExcelApp.Workbooks(2).Sheets(1).Cells.FormatConditions.Delete
objExcelApp.Workbooks(1).Sheets(1).Copy ,objExcelApp.Workbooks(2).Sheets(objExcelApp.Workbooks(2).Sheets.Count)
objExcelApp.Workbooks(2).Sheets(objExcelApp.Workbooks(2).Sheets.Count).Name = "Dummy_for_Comparison"
objExcelApp.Workbooks(2).Sheets(1).Activate
'To create a local formula the cell A1 is used
original_content = objExcelApp.Workbooks(2).Sheets(1).Cells(1,1).Formula
String sFormula
objExcelApp.Workbooks(2).Sheets(1).Cells(1,1).Formula = "=INDIRECT(""Dummy_for_Comparison" & "!""&ADDRESS(ROW(),COLUMN()))"
sFormula = objExcelApp.Workbooks(2).Sheets(1).Cells(1,1).FormulaLocal
objExcelApp.Workbooks(2).Sheets(1).Cells(1,1).Formula = original_content
'with the local formula the conditional formatting is used to mark the cells that are different
const xlCellValue = 1
const xlNotEqual = 4
objExcelApp.Workbooks(2).Sheets(1).Cells.FormatConditions.Add xlCellValue, xlNotEqual, sFormula
objExcelApp.Workbooks(2).Sheets(1).Cells.FormatConditions(1).Interior.ColorIndex = 3
_______________________________________________________________
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: users-help@tortoisesvn.tigris.org
Received on Wed Apr 25 21:21:05 2007