I seem not to be able to access a cell or a range using column and row number in Excel via Applescript.
Minimal example:
tell application "Microsoft Excel"
-- works
log range (get address row 1, column 1) of sheet 1 of active workbook
-- fails
set r to (range (get address row 1, column 1) of sheet 1 of active workbook)
end tell
Why does
log range (get address row 1, column 1) of sheet 1 of active workbook
work while
set r to (range (get address row 1, column 1) of sheet 1 of active workbook)
fails?
The
logcommand works because it is doing something very different than thesetcommand is attempting to do.The
setcommand is trying to set a variable to the results of an invalid statement. The result is an error.If you remove the commands from in front of the statement you will get the same error.
The key part is this below, which is not a valid range. Instead, it is an attempt to make a list containing two separate items (a string and a column) into a range object:
What
logis doing is more passive. This is from the Language GuideThe object specifier in this case is the range but it cannot be resolved as the syntax is incorrect. Therefore,
logshows the bits and pieces butsetfails.If you wish to have a single range that includes all of row 1 and all of column A, then this would work:
and instead to get the single cell at the intersection you can do:
You could also mimic the syntax of the result: