等待shell命令来完成 [英] Wait for shell command to complete

查看:323
本文介绍了等待shell命令来完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行在Excel VBA中一个简单的shell命令运行在指定的目录像下面的批处理文件:

I'm running a simple shell command in Excel VBA that runs a batch file in a specified directory like below:

Dim strBatchName As String
strBatchName = "C:\folder\runbat.bat"
Shell strBatchName

有时批处理文件可能需要更长一些的电脑上运行,并有继续VBA code,它是依赖于批处理文件来完成运行。我知道你可以设置一个等待计时器象下面这样:

Sometimes the batch file might take longer on some computer to run, and there are proceeding VBA code that is dependent on the batch file to finish running. I know you can set a wait timer like below:

Application.Wait Now + TimeSerial(0, 0, 5)

但是,这可能不是一些电脑太慢上工作。有没有一种方法,系统地告诉Excel中使用VBA code的其余部分进行到的之后的外壳已完成运行?

推荐答案

使用WScript.Shell的代替,因为它有一个 waitOnReturn 选项:

Use the WScript.Shell instead, because it has a waitOnReturn option:

Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1

wsh.Run "C:\folder\runbat.bat", windowStyle, waitOnReturn

(IDEA从等待外壳结束,然后设置单元格格式)

这篇关于等待shell命令来完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆