调用程序并等待程序返回运行结果
来源:岁月联盟
时间:2012-01-16
'创建日期: 2011-06-01,hellostory
'函数说明: 运行并等待程序执行完毕,同时返回程序运行结果
'参数说明: strCommand - 需要被执行的命令或程序
'返回值: 被执行的命令或程序自身返回的运行结果
'=========================================================================
Public Function runAndWaitExe(strCommand As String) As Integer
On Error GoTo errHandler
Dim WshShell As Object
Set WshShell = CreateObject("wscript.shell")
runAndWaitExe = WshShell.Run(strCommand, 0, True)
errHandler:
If Err.Number Then www.2cto.com
MsgBox "执行命令( " & strCommand & " )时发生错误:" & Err.Description, vbCritical, "错误"
Debug.Print strCommand
Resume Next
End If
End Function
摘自 hellostory的专栏