Automate the insert chart option in Microsoft excel using apple script

Hi all,
I would like to automate the insert chart in MS Office Excel for a fixed range of cells using AppleScript. Will it be possible to do it via apple script? If possible, kindly point me to the right tutorial to start with.

Here is some code to get you started:

tell application id "XCEL"
	activate
	set theSheet to worksheet 1 of (make new workbook)
	set theRange to range "a1:d4" of theSheet
	set value of theRange to {{"serie 1", "serie 2", "serie 3", "serie 4"}, {10.0, 15.0, 25.0, 5.0}, {30.0, 6.0, 13.0, 9.0}, {7.0, 22.0, 4.0, 19.0}}
	set theChart to make new chart at end of theSheet with properties {visible:sheet visible}
	tell theChart
		set chart style to 201 --column clustered
		-- add here other properties you want to set
	end tell
	set source data theChart source theRange plot by by rows
end tell

The best way to know how to set the chart properties is to create “by hand” a chart as you like it an then run this script:

tell application id "XCEL" 
	properties of active chart
end tell
1 Like