我想用下面的代码最小化shell窗口的执行和python脚本的执行:
Sub RunPython()
Dim oShell, oExec as Object
Dim sriptPath, scriptName, datas, oCmd as String
Dim weekNumber as Integer
Set oShell = CreateObject("WScript.Shell")
oCmd = "python.exe " & scriptPath & scriptName & " " & datas & " " & Str(weekNumber)
Set oExec = oShell.Exec(oCmd)
'We are waiting for the Shell script to be executed'
While oExec.Status = 0
Wend
MsgBox "Hagrid notebook update completed"
End Sub
必须保留oExec
对象的状态信息。我试图插入概念vbMinimizedFocus
,但它不起作用。你有解决这个难题的办法吗?
根据我的测试,这两个版本都使.Status
可用。
选项1.使用pythonw.exe
而不是python.exe
-它不会最小化窗口,而是完全在后台运行。
选项2.您可以在python脚本的开头添加2行:
import ctypes
ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 6 )