Uri*_*ren 26
最简单的方法是使用Shell命令运行python解释器
Shell ("python.exe " & yourScript & " " & arguments)
Run Code Online (Sandbox Code Playgroud)
Gab*_*bor 20
就在这里.我的首选这样做的方式是通过xlwings(https://www.xlwings.org/),但也有其他几个选项也是如此.XlWings很棒,因为它是免费的,开源的,易于使用的,具有出色的文档.但是有一些功能限制,因此您必须检查它是否符合您的需求.
Flo*_* B. 15
使用VBA运行python脚本有多种方法,具体取决于您是否需要等待执行结束并知道它是否没有错误.
使用Shell,与控制台异步:
Public Sub RunPython(file As String, ParamArray args())
Shell "python.exe """ & file & """ " & Join(args, " ")
End Sub
Run Code Online (Sandbox Code Playgroud)
使用Shell,无需控制台同步:
Public Function RunPython(file As String, ParamArray args())
Shell "pythonw.exe """ & file & """ " & Join(args, " ")
End Function
Run Code Online (Sandbox Code Playgroud)
使用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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10252 次 |
| 最近记录: |