我有一个简单的Python脚本(" hi.py"),如下所示
import time
print("HI")
time.sleep(5)
我正在使用Excel VBA拨打"" hi.py"按Windows Script Host's Run Method
(代码如下)。它有效。
sub testRun()
Dim wsh As Object
Dim a As Variant
Set wsh = CreateObject("WScript.Shell")
a = wsh.run("C:\tmpFolder\pyProject\myProject\hi.py", 1, True)
End Sub
但如果我使用Windows Script Host's Exec Method
而不是Run Method
,我的电脑会说hi.py is not a valid win 32 application
。
Sub testExec()
Dim wsh As Object, oexec As Object
Set wsh = CreateObject("WScript.Shell")
Set oexec = wsh.exec("C:\tmpFolder\pyProject\myProject\hi.py")
End Sub
如何使用Windows Script Host Exec Method
运行我的python脚本?
非常感谢你。
答案 0 :(得分:0)
方法exec()
需要一个可以传递给命令行的String。试试python C:\tmpFolder\pyProject\myProject\hi.py
或python3 C:\tmpFolder\pyProject\myProject\hi.py
,就像在CMD.exe