SD7 + Excel bug? (Update: not a bug)

It’s my first time trying out Script Debugger, and it seems to have an issue in dealing with multiple Excel documents. Here are the steps:

  1. Create a new Excel document, enter “1” at cell “A1”, save as “W1”.
  2. Create a new Excel document, enter “2” at cell “A1”, save as “W2”.
  3. Keep them open and run the following script in SD7:

tell application “Microsoft Excel”
set v1 to (value of cell “A1” of sheet 1 of workbook “W1”) + (value of cell “A1” of sheet 1 of workbook “W2”)
set v2 to (value of cell “A1” of sheet 1 of workbook 1) + (value of cell “A1” of sheet 1 of workbook 2)
end tell

v1 contains 4.0 (incorrect) while v2 contains 3.0 (correct). In short, I cannot access values in a saved, non-frontmost Excel document by its workbook name. Script Editor works fine. Would this be a SD7 bug?

I only have a very old version of Excel, but I get the same result in Script Debugger as you. However, I also get the same result in Script Editor. When I look at the log, It shows:

get value of cell "A1" of sheet 1 of workbook "W1"
--> 2.0
get value of cell "A1" of sheet 1 of workbook "W2"
--> 2.0

I suspect the problem is that your workbook names are incorrect, so Excel is returning the result for the first workbook in both cases. You probably need to include the extension. Try this:

tell application "Microsoft Excel"
	set v1 to (value of cell "A1" of sheet 1 of workbook "W1.xls") + (value of cell "A1" of sheet 1 of workbook "W2.xls")
	set v2 to (value of cell "A1" of sheet 1 of workbook 1) + (value of cell "A1" of sheet 1 of workbook 2)
end tell

Shane, you are right. I don’t know why I thought Script Editor didn’t have the same problem. What happens is that Excel gives me an invalid object error when doing:

set v1 to workbook "WRONG_NAME"

but does nothing on

set v1 to sheet 1 of workbook "WRONG_NAME"
or
set v1 to value of cell "A1" of sheet 1 of workbook "WRONG_NAME"

Thanks for correcting me!