VBA(Office 2011 for Mac)有没有办法运行AppleScript?

这个问题之前已经被问到了,但是build议的答案(“Office 2011 for Mac中的VBA Shell函数”)似乎不起作用。

我的Applescript,Run_Script.scpt,创build一个小的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。 我正在运行Office 2011 for Mac。 Excel已更新至14.7.2

我究竟做错了什么?

在Excel 2011(14.0.0)的ElCapitain上,下面的2个macros正在运行。 您必须调整path到您的驱动器/用户/脚本文件。

在VBAmacros中调用脚本:

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

在VBAmacros中调用应用程序:

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