Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
60 Second Countdown NOT using the WAIT function... Trevor Williams Excel Programming 18 October 28th 09 05:13 AM
Make VBA wait for return from external function Gib Bogle Excel Programming 8 January 3rd 09 03:42 AM
StatusBar not updating after Shell call and wait Don Wiss Excel Programming 0 May 17th 08 12:06 AM
wait function N+ Excel Programming 2 February 10th 08 10:17 PM
How can you wait for the SHELL command to terminate ? Dave Peterson[_3_] Excel Programming 1 October 1st 03 09:10 AM


All times are GMT +1. The time now is 04:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"