有多種方式TU運行使用VBA取決於你是否需要等待執行結束,知道一個python腳本如果它沒有錯誤。
隨着Shell,異步與控制檯:
Public Sub RunPython(file As String, ParamArray args())
Shell "python.exe """ & file & """ " & Join(args, " ")
End Sub
隨着Shell,同步而不控制檯:
Public Function RunPython(file As String, ParamArray args())
Shell "pythonw.exe """ & file & """ " & Join(args, " ")
End Function
隨着WScript.Shell,同步而不控制檯和與退出代碼:
Public Function RunPython(file As String, ParamArray args()) As Long
Dim obj As Object
Set obj = CreateObject("WScript.Shell")
RunPython = obj.Run("pythonw.exe """ & file & """ " & Join(args, " "), 0, True)
End Function
然後留新(以及遠離)VBA :)我希望你你找到你需要的東西。有趣的問題。 –
@ Jean-FrançoisFabre感謝您對這個問題的興趣。 :從我的角度來看,p –
(也適用於其他專有和繁瑣的系統),有時最好1)將數據導出爲CSV 2)運行python腳本以便輕鬆處理數據3)重新導入爲excel /無論如何我們也使用這個技巧,而不是試圖在子語言中編碼:) –