无法在Excel 2016 for MAC上从VBA调用Python脚本
当我运行以下并将一些parameter passing给我现有的Excel for Mac 2011的 Python脚本时,它的工作原理,但没有发生在Mac 2016的 Excel,即没有错误,没有结果。
#If Mac Then Private Declare Function system Lib "libc.dylib" (ByVal command As String) As Long Const python3Dir As String = "/usr/local/bin/python3" #End If Sub btnScrape_Click() ' Uses system() to run external command ' system() only returns the exit code. If you want to get the output from the command, Dim result As String Dim command As String Dim myDir As String myDir = getPosixPath(ThisWorkbook.Path) command = "cd " & myDir & " && " & python3Dir & " myPythonScript.py ######## ####" Debug.Print command result = system(command) Debug.Print result ' 0 means OK. MsgBox "Check report.txt" End Sub Function getPosixPath(macPath As String) As String Dim scriptToRun As String scriptToRun = "tell application ""Finder""" & Chr(13) scriptToRun = scriptToRun & "set appUserPath to POSIX path of " & """" & macPath & """" & Chr(13) scriptToRun = scriptToRun & "end tell" & Chr(13) getPosixPath = MacScript(scriptToRun) End Function
Python设置:
which -a python3 /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 /usr/local/bin/python3 which -a python /usr/bin/python echo $PATH /Library/Frameworks/Python.framework/Versions/3.5/bin/python3
是否有什么具体的,需要修改/添加为Mac 2016的 Excel?