【发布时间】:2014-07-28 15:42:39
【问题描述】:
此宏在 Excel 2011 for Mac 上运行良好:
Sub Works()
scriptToRun = "do shell script ""/anaconda/bin/python -c "" & quoted form of ""import test_file"" "
res = MacScript(scriptToRun)
Debug.Print res
End Sub
对应的test_file.py 文件(将它放在pythonpath 的某处)是:
import sys
print(sys.version)
但是,当我涉及appscript Python 包时,它会冻结很长时间并且什么都不做。将test_file.py 文件更改为此(pip install appscript 首先):
import appscript
app = appscript.app('Microsoft Excel')
app.cells['A1'].value.set(2)
但是当我直接从 AppleScript 编辑器运行命令时,它可以工作:
do shell script "/anaconda/bin/python -c " & quoted form of "import test_file"
如何在 Mac 上的 Excel VBA 中调用它? (顺便说一句,在 Windows 上,它可以轻松地与 WScript.Shell 和 pywin32 一起使用)
【问题讨论】: