首先我解决了在Conda环境下使用AppleScript执行Python的问题:如何在Apple系统中使用AppleScript执行Python?
现在我必须从我的 vba 代码运行 applescript,但我有错误或无操作。
文件和脚本与之前的链接相同,vba 代码:
第一次测试
Sub RunScript0()
Dim myScriptResult As String
myScriptResult = AppleScriptTask("/Users/andrea/Library/Application Scripts/com.microsoft.Excel/MyAppleScriptFile.scpt", "MyAppleScriptHandler", "/usr/bin/python3 /Users/andrea/Desktop/pymac/test.py")
End Sub
第二次测试
Sub RunScript1()
Dim scriptPath As String
Dim command As String
' Set the path to your AppleScript file
scriptPath = "/Users/andrea/Library/Application Scripts/com.microsoft.Excel/run_script.scpt"
' Build the full command
command = "osascript """ & scriptPath & """"
' Run the command using the Shell function
Call Shell(command, vbNormalFocus)
End Sub
代码错误,无操作。
适用于苹果电脑的 Excel 365 osX 索诺玛 14.2
我简单地解决了:
on myapplescripthandler(paramString)
do shell script "/usr/bin/python3 " & paramString
end myapplescripthandler
我的调用applescript的vba代码:
子运行脚本()
Dim res As String
Dim myScriptResult As String
myScriptResult = AppleScriptTask("PythonTest.scpt", _
"myapplescripthandler", _
"/Users/andrea/Desktop/pymac/test.py")
MsgBox myScriptResult
End Sub
就这些了,希望对你有帮助