VBScript - How to make program wait until process has finished?

后端 未结 4 1385
深忆病人
深忆病人 2020-12-02 01:54

I have a problem in a VBScript that I am using with a VBA/Excel macro and a HTA. The problem is just the VBScript, I have the other two components, i.e. the VBA macro and HT

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 02:24

    You need to tell the run to wait until the process is finished. Something like:

    const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
    set oShell = WScript.CreateObject("WScript.Shell")
    command = "cmd /c C:\windows\system32\wscript.exe \myScript.vbs " & args
    oShell.Run command, DontShowWindow, WaitUntilFinished
    

    In the script itself, start Excel like so. While debugging start visible:

    File = "c:\test\myfile.xls"
    oShell.run """C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"" " & File, 1, true
    

提交回复
热议问题