VBA(Office 2011 for Mac)有没有办法运行AppleScript?
问题描述:
此问题之前已被问到,但建议的答案(“Office 2011 for Mac中的VBA Shell函数”)似乎不起作用。VBA(Office 2011 for Mac)有没有办法运行AppleScript?
我的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。我正在运行Office 2011 for Mac。 Excel已经更新到14.7.2
我在做什么错?
答
在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)
那些很好地工作!非常感谢你! –