I’m trying to GUI script the Excel VBE. Using UI Browser, the Applescript seems to be
Tell process "Microsoft Excel"
tell menu bar -- (menu bar 1)
tell menu bar item "Edit" -- (menu bar item 4)
tell menu -- (menu 1)
click menu item "Select All" -- (menu item 8)
end tell
end tell
end tell
end tell
However, Script Debugger doesn’t like the line ‘tell menu bar item “Edit”’ with the error “Expected end of line but found class name.” I don’t know how to fix that (or understand it even.) I did try to do it by number (4).
My apologies for the confusion. The above was only the tell-chain reported by UI Browser The complete code is:
tell application "Microsoft Excel" to activate
tell application "System Events"
Tell process "Microsoft Excel"
tell menu bar -- (menu bar 1)
tell menu bar item "Edit" -- (menu bar item 4)
tell menu -- (menu 1)
click menu item "Select All" -- (menu item 8)
end tell
end tell
end tell
end tell
end tell
The error from Script Debugger is "Expected end of line but found class name.” reported on the 'tell menu bar item “Edit”” line. Visually, “Edit” is the 4th menu over. I just can’t see the error.
I find UI Browser very counter-intuitive to use, probably because I only use it a few times a year. But the above seems to make sense.
In reviewing yesterday’s work, I see that menu bar 1 is Excel’s spreadsheet menu. The VBE’s menu is ‘top level function row (UI element 40)’ So the new code is:
tell application "Microsoft Excel" to activate
tell application "System Events"
Tell process "Microsoft Excel"
tell top level function row -- (UI element 40)
tell menu bar item "Edit" -- (menu bar item 4)
tell menu -- (menu 1)
click menu item "Select All" -- (menu item 8)
end tell
end tell
end tell
end tell
end tell
The error is now on that line "tell top level function row – (UI element 40)” as “Expected end of line but found identifier.”
tell application "Microsoft Excel" to activate
tell application "System Events"
tell process "Microsoft Excel"
tell UI element 40
tell menu bar item "Edit" -- (menu bar item 4)
tell menu 1
tell menu item "Select All" -- (menu item 8)
click
end tell
tell menu item "Copy"
click
end tell
end tell
end tell
end tell
end tell
end tell
Thanks Martin. Some time you have to use the names, and some times the numbers.
I think your problem in your original script was in omitting a valid index key in lines 2 and 4. You actually had the correct reference in the comment made against both of these lines.