我参考了这里给出的答案 -如何在Excel VBA上调用Python脚本? https://stackoverflow.com/questions/18135551/how-to-call-python-script-on-excel-vba但这对我不起作用。
我只是看到屏幕在我面前闪烁,而 Python 脚本根本不运行。我正在编写的Python脚本位于Spyder中,并且有多个模块引用它。
这是我正在编写的代码:
Sub RunPythonScript()
Dim objShell As Object
Dim PythonExePath As String, PythonScriptPath As String
ActiveWorkbook.Save
ChDir "C:\path\where\.py\file\is\saved"
Set objShell = VBA.CreateObject("Wscript.Shell")
PythonExePath = """C:\path\where\python.exe\exists"""
PythonScriptPath = """C:\path\where\.py\file\is\saved"""
objShell.Run PythonExePath & PythonScriptPath
Application.Goto Reference:="RunPythonScript"
objShell.Popup "Your results are now processed", , "Attention!"
End Sub
尝试这样:
Sub RunPythonScript()
Dim exe, pth
exe = "C:\path\where\python.exe\exists"
pth = "C:\path\where\.py\file\is\saved"
Shell "cmd.exe /k """"" & exe & """ """ & pth & """""", vbNormalFocus
MsgBox "Your results are now processed", vbInformation, "Attention!"
End Sub
https://www.myonlinetraininghub.com/vba-shell https://www.myonlinetraininghub.com/vba-shell
我不知道你的是什么Application.Goto
is for.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)