Applescript控制excel在优胜美地?

时间:2014-11-05 00:47:54

标签: excel applescript

我有一个控制Microsoft Excel的AppleScript。我需要与System Events对话,点击一些对话框按钮。现在,在升级(原文如此)到Yosemite之后,脚本在两个错误之间交替出现(!!):

  1. "系统事件出错:连接无效。"编号-609,光标在"打开wbfile"
  2. ' docuement" tst"不能打开。系统事件无法以" Microsoft Excel 97-2004工作表格式打开文件。'此错误在对话框中给出,然后单击“确定”。使脚本能够成功完成。
  3. 不知何故,打开一个工作簿,告诉进程" 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
    

1 个答案:

答案 0 :(得分:0)

您可以使用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

问候,迈克尔/汉堡