The following AppleScript code sets the size of the last chart added to a sheet in Excel - to 30cm wide and 20cm tall. (I experimented with the numerical values but I don’t understand them.)
tell application "Microsoft Excel"
tell active sheet
tell last chart object
set height to 567
set width to 850.5
end tell
end tell
end tell
This was tough as there’s not much on the web about this.
I have a question, though:
How to I get the selected chart, not just the last one added? (Usually the last one added is the one I want to resize but I’d rather not assume that.)
(The above script will be run from Keyboard Maestro, and probably triggered by a button in Metagrid.)
I don’t have Excel on the Mac, only my work PC; but the chart section of this old documentation would seem to suggest active chart would do it. I just can’t test it to confirm.
That would be a useful document, and I have it already.
active chart doesn’t get me very far as apparently it’s the chart object (sic) I can set height and width for, not a chart. In my code I have last chart object. I apparently (I’ve tested it) can’t set the height or width for active chart nor find the associated chart object.
Thank you! I’m finding the Excel Applescript data model fiddly in the extreme.
(There are a few tricks with it I may well put into a blog post - as finding stuff on the web has proven difficult. I hope you don’t mind if I include this.)