2

我想用下面的代码最小化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,但它不起作用。你有解决这个困难的想法吗?

4

1 回答 1

1

根据我的测试,这两个版本都.Status可用。

选项 1. 使用pythonw.exe而不是python.exe- 它不会最小化窗口,而是在后台完全运行它。

选项 2。您可以在 python 脚本的开头添加 2 行:

import ctypes
ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 6 )
于 2020-02-18T14:29:41.303 回答