Given a cell I can return that cell’s worksheet, but I can’t figure out how to get it’s workbook.
The external argument of the get address command seems to fail.
Manualy keeping track of the workbook’s name would be a huge hassle, but doable, better avoided if possible.
Given a cell, how can I return the workbook object in which that cell resides?
tell application "Microsoft Excel"
set myCell to get range "A1" of worksheet "Sheet2" of workbook "Workbook1.xls"
name of worksheet object of myCell -- returns "Sheet2"
get address of myCell with external -- returns "$A$1"
end tell
I don’t see a direct way in the dictionary, but there is an indirekt way
tell application "Microsoft Excel"
set myCell to get range "A1" of worksheet "Sheet2" of workbook "Workbook1.xls"
try
areas of myCell as real
on error e
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "["}
set theWorkBook to text item 2 of e
set AppleScript's text item delimiters to "]"
set theWorkBook to text item 1 of theWorkBook
set AppleScript's text item delimiters to ASTID
end try
end tell
theWorkBook