1

I have been using Excel charts for some years for creating computer animated movies for teaching physics. However, in converting from VBA to AppleScript I have had trouble saving the charts as .jpeg files. I have tried the script below:

tell application "Microsoft Excel"
 set filebasename to get value of cell "MovieName"
 activate object chart object filebasename of sheet 1
 set testfile to "test.jpg"
 save as picture active chart picture type save as JPG file file name testfile
end tell

but AppleScript editor tells me the active chart doesn't understand the save as picture instruction. My work-around has been to use the script:

tell application "Microsoft Excel"
 set filebasename to get value of cell "MovieName"
 activate object chart object filebasename of sheet 1
 copy picture active chart appearance screen format picture
end tell

and then past the clipboard into GraphicConverter to get a .jpeg file.

What am I doing that's stupid?

pnuts
  • 58,317
  • 11
  • 87
  • 139

1 Answers1

0
tell application "Microsoft Excel"
    set theValue to get value of cell "A1"
    set myNewChartObject to make new chart object at sheet 1 with data theValue with properties {width:100.0, height:100.0}
    save as picture myNewChartObject picture type save as JPG file file name (((path to desktop folder) as text) & "myChart.jpg") as text
end tell

Add salt to taste. A small dissection of what's here...

The make command is used to create just about every kind of object and returns for you the object that was created. activate doesn't, and that's probably why save as picture failed, because you didn't have an object to actually save. I would hazard to guess active chart isn't enough for the command to go by because the object that is currently active could change without you realizing it. It is generally a good idea to grab the object, apply it to a variable, and pass that around instead because then you know what you have to work with.

Philip Regan
  • 5,005
  • 2
  • 25
  • 39