1 ' extensions: xls;xlsx;xlsm;xlsb;xlam
3 ' TortoiseSVN Diff script for Excel files
5 ' Copyright (C) 2004-2008 the TortoiseSVN team
6 ' This file is distributed under the same license as TortoiseSVN
9 ' $Author: tortoisesvn $
10 ' $Date: 2009-10-18 09:25:24 +0200 (So, 18. Okt 2009) $
14 ' Michael Joras <michael@joras.net>, 2008
18 dim objExcelApp
, objArgs
, objScript
, objBaseDoc
, objNewDoc
, objWorkSheet
, i
20 Set objArgs
= WScript
.Arguments
23 MsgBox
"Usage: [CScript | WScript] compare.vbs base.doc new.doc", vbExclamation
, "Invalid arguments"
30 Set objScript
= CreateObject("Scripting.FileSystemObject")
31 If objScript
.FileExists(sBaseDoc
) = False Then
32 MsgBox
"File " + sBaseDoc
+" does not exist. Cannot compare the documents.", vbExclamation
, "File not found"
35 If objScript
.FileExists(sNewDoc
) = False Then
36 MsgBox
"File " + sNewDoc
+" does not exist. Cannot compare the documents.", vbExclamation
, "File not found"
40 Set objScript
= Nothing
43 Set objExcelApp
= Wscript
.CreateObject("Excel.Application")
44 If Err
.Number
<> 0 Then
45 Wscript
.Echo
"You must have Excel installed to perform this operation."
49 'Open base excel sheet
50 objExcelApp
.Workbooks
.Open sBaseDoc
52 objExcelApp
.Workbooks
.Open sNewDoc
54 objExcelApp
.Visible
= True
55 'Create a compare side by side view
56 objExcelApp
.Windows
.CompareSideBySideWith(objExcelApp
.Windows(2).Caption
)
57 If Err
.Number
<> 0 Then
58 objExcelApp
.Application
.WindowState
= xlMaximized
59 objExcelApp
.Windows
.Arrange(-4128)
62 'Mark differences in sNewDoc red
65 For Each objWorkSheet
In objExcelApp
.Workbooks(2).Worksheets
67 objworksheet
.Cells
.FormatConditions
.Delete
69 objExcelApp
.Workbooks(1).Sheets(i
).Copy
,objExcelApp
.Workbooks(2).Sheets(objExcelApp
.Workbooks(2).Sheets
.Count
)
71 objExcelApp
.Workbooks(2).Sheets(objExcelApp
.Workbooks(2).Sheets
.Count
).Name
= "Dummy_for_Comparison" & i
74 'To create a local formula the cell A1 is used
75 original_content
= objworksheet
.Cells(1,1).Formula
77 'objworksheet.Cells(1,1).Formula = "=INDIRECT(""" & objExcelApp.Workbooks(2).Sheets(i).name & " (2)"& "!""&ADDRESS(ROW(),COLUMN()))"
78 objworksheet
.Cells(1,1).Formula
= "=INDIRECT(""Dummy_for_Comparison" & i
& "!""&ADDRESS(ROW(),COLUMN()))"
79 sFormula
= objworksheet
.Cells(1,1).FormulaLocal
81 objworksheet
.Cells(1,1).Formula
= original_content
82 'with the local formula the conditional formatting is used to mark the cells that are different
85 objworksheet
.Cells
.FormatConditions
.Add xlCellValue
, xlNotEqual
, sFormula
86 objworksheet
.Cells
.FormatConditions(1).Interior
.ColorIndex
= 3