|
我们用shell()来执行外部的程序时,一旦shell启动了外部程序后无论外部程序是否已经运行完毕,Access 都会继续执行 shell 语句下面的 VBA 程序。若要 Access 等待 shell() 调用的外部程序执行完毕后再继续执行下面的 VBA 程序可使用以下方法:'以下语句加入窗体声明段Private Declare Function OpenProcess Lib"kernel32" (ByVal dwDesiredaccess&, ByVal bInherithandle&, ByValdwProcessid&) As LongPrivate Declare Function GetExitCodeProcessLib "kernel32" (ByVal hProcess As Long, lpexitcode As Long) As LongConst STILL_ACTIVE = &H103Const PROCESS_QUERY_INFORMATION = &H400Dim hShell As LongDim hProc As LongDim lExit As Long'更改您的shell语句为如下格式: hShell = Shell("RunExeFile", 1) hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hShell) If hShell = 0 Then MsgBox "程序执行失败" Do GetExitCodeProcess hProc, lExit DoEvents Loop While lExit = STILL_ACTIVE MsgBox "Shell 语句执行完毕" |
|
共 1 个关于本帖的回复 最后回复于 2013-7-2 11:30