Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default waiting for an .exe file that runs

Hi all,

I accomplish to make an .exe file run but the call sub i've written
below seem to execute without caring at the end of the .exe file.
Only if I put the msgbox, this can block excel in running and let
the .exe file finish.
any help?

the rilevant part of the code is:


Option Explicit

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type


Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type


Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA _
Lib "kernel32" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long


Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = 32


Sub test()



ExecCmd "Y:\programs\Sel.exe", 2000, True

'MsgBox "ok", vbInformation
Call GetTextFile
Call copy

End Sub



Function ExecCmd(sCmdLine As String, _
lmSecsWait As Long, _
Optional bShowWindow As Boolean) As Long


'will start an external process and
'wait till this process is finished
'returns -1 if successfull and -1 if not
'-----------------------------------------
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lReturn As Long


'Initialize the STARTUPINFO structu
With Start
.cb = Len(Start)
.dwFlags = 1 'hexadecimal would be &H1
If bShowWindow Then
.wShowWindow = 1
End If
End With


'Start the shelled application:
lReturn = CreateProcessA(sCmdLine, _
vbNullString, _
0, _
0, _
1, _
NORMAL_PRIORITY_CLASS, _
0, _
"Y:\RUNNING\Valassis\gemelli", _
Start, _
proc)


'Wait for the shelled application to finish:
lReturn = WaitForSingleObject(proc.hProcess, lmSecsWait)
test1
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hThread
CloseHandle proc.hProcess
ExecCmd = lReturn
End Function



Sub test1()


Dim cSK As clsSendKeys


Set cSK = New clsSendKeys


cSK.SendString "TEST", False
cSK.PressKeyVK keyReturn
cSK.PressKeyVK keyReturn


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default waiting for an .exe file that runs

Look for the "Shell and Wait" example in he

http://www.appspro.com/Tips/VBA%20Tips.htm


--
Hope that helps.

Vergel Adriano


"Marco" wrote:

Hi all,

I accomplish to make an .exe file run but the call sub i've written
below seem to execute without caring at the end of the .exe file.
Only if I put the msgbox, this can block excel in running and let
the .exe file finish.
any help?

the rilevant part of the code is:


Option Explicit

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type


Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type


Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA _
Lib "kernel32" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long


Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = 32


Sub test()



ExecCmd "Y:\programs\Sel.exe", 2000, True

'MsgBox "ok", vbInformation
Call GetTextFile
Call copy

End Sub



Function ExecCmd(sCmdLine As String, _
lmSecsWait As Long, _
Optional bShowWindow As Boolean) As Long


'will start an external process and
'wait till this process is finished
'returns -1 if successfull and -1 if not
'-----------------------------------------
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lReturn As Long


'Initialize the STARTUPINFO structu
With Start
.cb = Len(Start)
.dwFlags = 1 'hexadecimal would be &H1
If bShowWindow Then
.wShowWindow = 1
End If
End With


'Start the shelled application:
lReturn = CreateProcessA(sCmdLine, _
vbNullString, _
0, _
0, _
1, _
NORMAL_PRIORITY_CLASS, _
0, _
"Y:\RUNNING\Valassis\gemelli", _
Start, _
proc)


'Wait for the shelled application to finish:
lReturn = WaitForSingleObject(proc.hProcess, lmSecsWait)
test1
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hThread
CloseHandle proc.hProcess
ExecCmd = lReturn
End Function



Sub test1()


Dim cSK As clsSendKeys


Set cSK = New clsSendKeys


cSK.SendString "TEST", False
cSK.PressKeyVK keyReturn
cSK.PressKeyVK keyReturn


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default waiting for an .exe file that runs

thanks a lot

I found the solution.

Marco

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
VBA macro runs fine, but freezes if I try to do ANYTHING else whileit runs Rruffpaw Setting up and Configuration of Excel 1 September 17th 11 01:25 PM
Pausing or waiting in VBA Brad Excel Programming 2 November 6th 06 05:07 PM
Waiting... Rob Hargreaves[_2_] Excel Programming 1 August 7th 05 05:11 PM
in a excel file, how to make a menu item for the .xls file that when clicked on it runs myform.show? example plz Daniel Excel Worksheet Functions 1 July 7th 05 03:52 AM
waiting Mark Kubicki Excel Programming 2 August 7th 03 09:08 PM


All times are GMT +1. The time now is 04:38 AM.

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"