【问题标题】:Is there any way for VBA (in Office 2011 for Mac) to run an AppleScript?VBA(在 Office 2011 for Mac 中)有什么方法可以运行 AppleScript?
【发布时间】:2018-03-05 15:31:28
【问题描述】:

以前有人问过这个问题,但建议的答案(“Office 2011 for Mac 中的 VBA Shell 函数”)似乎不起作用。

我的 Applescript Run_Script.scpt 创建了一个小的 txt 文件。它在编辑器中完美运行。编译为应用程序并在桌面上双击时也能完美运行。

我需要从 VBA 过程中调用它。我试过这些:

Sub sub_scripttest()

Dim i As Integer
Dim result_long As Long
Dim result_str As String

'//==  the original question was this:
result_str = Shell("Macintosh HD:Applications:Run_Script.app", vbNormalFocus)
result_str = Shell("Macintosh HD/Applications/Run_Script.app", vbNormalFocus)
'//== gives a modal dialog box:  "Runtime error 53: File not found"

'//==  the suggested solution was this:
result_str = MacScript("do shell script ""Macintosh HD:Applications:Run_Script.app""")
result_str = MacScript("do shell script ""Macintosh HD/Applications/Run_Script.app""")
'//== gives a modal dialog box: "Runtime error 5: Invalid Procedure call or Argument"

'//==  another suggested solution was this:
result_long = system("Macintosh HD:Applications:Run_Script.app")
result_long = system("Macintosh HD/Applications/Run_Script.app")
'//==  appears to run, but returns   result_long=32512,   which is not a successful termination code.
'//==  also the desktop shows that the script did not run. The txt file was not created.

'//==  I even tried:
result_str = AppleScriptTask("Run_Script.scpt", "my_command", "")
'//==  and got: "Compile Error: Sub or Function not defined."

End Sub

我有 OS X El Capitan 10.11.6。我正在运行适用于 Mac 的 Office 2011。 Excel 已更新至 14.7.2

我做错了什么?

【问题讨论】:

    标签: vba macos excel applescript


    【解决方案1】:

    在使用 Excel 2011 (14.0.0) 的 ElCapitain 上,以下 2 个宏正在运行。 您必须调整驱动器/用户/脚本文件的路径。

    在 VBA 宏中调用脚本:

    s = "run script (""ElCapitain:Users:imac27:Desktop:Test_Script.scpt"" as alias)"
    Temp = MacScript(s)
    

    在 VBA 宏中调用应用程序:

    s = "run script (""ElCapitain:Users:imac27:Desktop:Test_App.app"" as alias)"
    Temp = MacScript(s)
    

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      相关资源
      最近更新 更多