开发者

How to get excel to insert a new image with Applescript?

I have the following Applescript:

tell application "Microsoft Excel"
    tell active workbook
        make new picture at end with properties {save with document:true, file name:"/Users/yuval/Pictures/foobar.jpg"}
    end tell
end tell

According to several sources, this should work.

However, every time I run the script I get the message

Microsoft Excel got an error: Can’t make class picture.

In the description, I see the error

error "Microsoft Excel got an error: Can’t make class picture." number -2710 from picture to class

After two hours of searching, I have absolutely no clue what to do. Any help would be greatly appreciated!


Details: Running Microsoft Excel 2011 on Mac OS开发者_开发知识库 X 10.7 Lion


Two things, though the caveat here is that I am working in Excel 2008, but Applescript implementations don't change substantially without fanfare:

First, make sure you are using the proper file path format. Applescript historically works with HFS paths, not POSIX

set theFilePath to "Macintosh HD:Users:UserName:Path:To:File.pic" --choose file

Second, make sure you are acting on the appropriate object. I was able to make this work with active sheet because active workbook wasn't a property in the Dictionary:

tell application "Microsoft Excel"
    tell active sheet
        make new picture at end with properties {file name:theFilePath}
    end tell
end tell

The above code combined worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜