Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
shell function + wait parameter
hi all i found this page..
http://msdn.microsoft.com/en-us/libr...yk(VS.80).aspx i need the wait parameter to be activated for my shell ... x = Shell("C:\abc.exe") can anybody show me the right syntax if the case is possible..? tx all |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
shell function + wait parameter
There is no "wait parameter" for the Shell command; however, you can make
your code wait using some simple Windows API calls. Follow these instructions to see how... Go to the VBA editor and add a Module (Insert/Module from the menu bar) and then copy/paste these lines in its (General)(Declarations) section: Public Declare Function OpenProcess _ Lib "kernel32" _ (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Public Declare Function CloseHandle _ Lib "kernel32" _ (ByVal hObject As Long) As Long Public Declare Function WaitForSingleObject _ Lib "kernel32" _ (ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) As Long Now, in your own code, call your Shell command in this format with the appropriate Shell arguments placed in the parentheses: PID = Shell( <<Put Shell Arguments Here ) Next, paste the following IMMEDIATELY after the PID=Shell statement above (making sure to handle the possible error where indicated; i.e. stop the code from falling through to your other commands if the Shell failed): If PID = 0 Then ' 'Handle Error, Shell Didn't Work ' Else hProcess = OpenProcess(&H100000, True, PID) WaitForSingleObject hProcess, -1 CloseHandle hProcess End If And finally, Dim both the PID and hProcess variables as Long. Now, when you run your code, it will wait for the Shell command to finish (if you are actually opening the Command Window, your code will wait for you to Exit from it). -- Rick (MVP - Excel) "pls123" wrote in message ... hi all i found this page.. http://msdn.microsoft.com/en-us/libr...yk(VS.80).aspx i need the wait parameter to be activated for my shell ... x = Shell("C:\abc.exe") can anybody show me the right syntax if the case is possible..? tx all |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
shell function + wait parameter
hi rick ty for your help !
can it use timeout, for being sure that excel will not hang if there is any error from the launched program..?? where should i indicate ? "Rick Rothstein" wrote: There is no "wait parameter" for the Shell command; however, you can make your code wait using some simple Windows API calls. Follow these instructions to see how... Go to the VBA editor and add a Module (Insert/Module from the menu bar) and then copy/paste these lines in its (General)(Declarations) section: Public Declare Function OpenProcess _ Lib "kernel32" _ (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Public Declare Function CloseHandle _ Lib "kernel32" _ (ByVal hObject As Long) As Long Public Declare Function WaitForSingleObject _ Lib "kernel32" _ (ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) As Long Now, in your own code, call your Shell command in this format with the appropriate Shell arguments placed in the parentheses: PID = Shell( <<Put Shell Arguments Here ) Next, paste the following IMMEDIATELY after the PID=Shell statement above (making sure to handle the possible error where indicated; i.e. stop the code from falling through to your other commands if the Shell failed): If PID = 0 Then ' 'Handle Error, Shell Didn't Work ' Else hProcess = OpenProcess(&H100000, True, PID) WaitForSingleObject hProcess, -1 CloseHandle hProcess End If And finally, Dim both the PID and hProcess variables as Long. Now, when you run your code, it will wait for the Shell command to finish (if you are actually opening the Command Window, your code will wait for you to Exit from it). -- Rick (MVP - Excel) "pls123" wrote in message ... hi all i found this page.. http://msdn.microsoft.com/en-us/libr...yk(VS.80).aspx i need the wait parameter to be activated for my shell ... x = Shell("C:\abc.exe") can anybody show me the right syntax if the case is possible..? tx all |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
60 Second Countdown NOT using the WAIT function... | Excel Programming | |||
Make VBA wait for return from external function | Excel Programming | |||
StatusBar not updating after Shell call and wait | Excel Programming | |||
wait function | Excel Programming | |||
How can you wait for the SHELL command to terminate ? | Excel Programming |