【问题标题】:Applescript controlling excel broken in yosemite?Applescript控制excel在优胜美地坏了?
【发布时间】:2014-11-05 00:47:53
【问题描述】:

我有一个控制 Microsoft Excel 的小程序。我需要与系统事件交谈以单击一些对话框按钮。现在,在升级(原文如此)到 Yosemite 之后,脚本在两个错误之间交替出现(!!):

  1. “系统事件出错:连接无效。”数字 -609,光标在“打开 wbfile”
  2. '无法打开文档“tst”。系统事件无法打开“Microsoft Excel 97-2004 工作表格式”的文件。此错误在对话框中给出,之后单击“确定”可使脚本成功完成。

不知何故,在“告诉进程“Microsoft Excel”中打开工作簿不起作用。 我可以在“告诉应用程序“Microsoft Excel”中打开工作簿就好了,但是 我无法按下对话框按钮。

任何帮助表示赞赏!!!

set wbfile to "/private/tmp/tst.xls"
tell application "Microsoft Excel"
    activate
end tell
delay 0.1
tell application "System Events"
    delay 0.1
    tell process "Microsoft Excel"
        delay 0.1
        set foo to open wbfile
        try
            set cancel to button "Cancel" of window 1
            click (cancel)
        end try
        try
            set macros to button "Enable Macros" of window 1
            click macros
        end try
        try
            set links to button "Ignore Links" of window 1
            click links
        end try
    end tell
end tell

set dat to "flflfl"
set output to (dat as string)
return output

【问题讨论】:

    标签: excel applescript


    【解决方案1】:

    您可以使用ignoring application responses 并让 Excel 打开文件而无需等待应用程序的反馈。该脚本将立即进入下一步。 之后系统事件可以点击按钮:

    set wbfile to "/private/tmp/tst.xls"
    ignoring application responses
        tell application "Microsoft Excel"
            activate
            set foo to open wbfile
        end tell
    end ignoring
    delay 1
    tell application "System Events"
        tell process "Microsoft Excel"
            try
                set cancel to button "Cancel" of window 1
                click (cancel)
            end try
            try
                set macros to button "Enable Macros" of window 1
                click macros
            end try
            try
                set links to button "Ignore Links" of window 1
                click links
            end try
        end tell
    end tell
    

    你好,迈克尔/汉堡

    【讨论】:

    • 太棒了!!我很高兴了解“忽略应用程序响应”。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多