【问题标题】:How to get excel to insert a new image with Applescript?如何让 excel 使用 Applescript 插入新图像?
【发布时间】:2011-10-27 03:23:40
【问题描述】:

我有以下 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

根据几个来源,这应该有效。

但是,每次我运行脚本时都会收到消息

Microsoft Excel 出现错误:无法制作班级图片。

在描述中,我看到了错误

错误“Microsoft Excel 出现错误:无法制作班级图片。”数字 -2710 从图片到课堂

经过两个小时的搜索,我完全不知道该怎么做。任何帮助将不胜感激!


详情: 在 Mac OS X 10.7 Lion 上运行 Microsoft Excel 2011

【问题讨论】:

    标签: excel automation applescript ms-office ui-automation


    【解决方案1】:

    有两件事,虽然这里需要注意的是我在 Excel 2008 中工作,但 Applescript 实现不会大张旗鼓地发生实质性变化:

    首先,确保您使用正确的文件路径格式。 Applescript 历来适用于 HFS 路径,而不是 POSIX

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

    其次,确保您正在对适当的对象进行操作。我能够使用active sheet 完成这项工作,因为active workbook 不是字典中的属性:

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

    上面的代码组合对我有用。

    【讨论】:

    • 将 POSIX 路径更改为 HFS 路径解决了我的问题。再次,非常感谢你!
    猜你喜欢
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多