What is the correct code to get an existing cell comment?
The following block of code “seems to work” to access desired cell values from an Excel file. I note, “seems to work” only because while I’m certain of the employee name match and the other values (i.e. found row, hire date and affiliated company), I can’t tell if I’ve successfully captured the comment which holds the employee’s position title associated with cell “B:found row”.
tell application “Microsoft Excel”
set searchRange to range ((“B” & Brunswick_Start as text) & “:B” & Ranger_End as text)
set foundRange to find searchRange what PAF_Employee with match case
set fRow to first row index of foundRange
set rDate to value of range (“L” & fRow as text)
set rCompany to value of range (“C” & fRow as text)
set rTitle to its Excel comment of range ("B" & fRow as text)
select foundRange
end tell
After numerous searches, I’ve only found the 2007 code below at MacTECH to set a cell comment and I’m not sure it correctly gets the comment of a cell as I’ve tried to use above. I get the “Can’t make «class X229» of «class ccel» “B27” of application “Microsoft Excel” into type text” error when attempting to use the comment variable rTitle as text.
In AppleScript:
tell application “Microsoft Excel”
tell range “A10” of active sheet
set cmt to its Excel comment – no error if nothing (dummy comment)
set vis to visible of cmt --get any property , returns missing value if empty
if vis is missing value then
set cmt to add comment
end if
end tell
tell cmt
Excel comment text text "My comment" --overwrites, but omit 'over write'!
set visible to true
select its shape object -- to allow editing
end tell
end tell