|
-
Apr 19th, 2000, 09:03 AM
#1
Thread Starter
Junior Member
I've developed an .exe that is fired from excel and winds up displaying it's results in a word document. After the user presses a command button on a worksheet, my .exe runs via a "shell" statement. Is there a better (or other) way to run the .exe?
An an answer would be very much appreciated.
-
Apr 19th, 2000, 09:14 AM
#2
Conquistador
you could try the "start" statement?
-
Apr 19th, 2000, 09:37 AM
#3
Thread Starter
Junior Member
"start" statement?
da_silvy suggested using "start" to run an .exe from an excel macro as an alternative to "shell". I couldn't locate "start" in any of the books I have nor at the microsoft vb site. Can any one elaborate on start?
Thanks
-
Apr 19th, 2000, 10:16 AM
#4
Conquistador
sorry, i think that function might only be availiable in vb 5/6 i think shell will probably be the most effective way to execute an executable..
-
Apr 19th, 2000, 10:22 AM
#5
Shell
What is wrong with the Shell start? What are you trying to do other then start the .exe? You can pass command line arguments, or use API calls or use a Wait function to see when it is finished.
-
Apr 19th, 2000, 05:25 PM
#6
Member
I think this way would be nicer:
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 CommandLine As String
Private ErrCode As Long
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 Long, 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 Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As
Long, _
lpExitCode As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public Function ExecCmd(cmdline$) As Long
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <> 258
ReturnValue = GetExitCodeProcess(proc.hProcess, ExecCmd)
ReturnValue = CloseHandle(proc.hProcess)
End Function
Sub Start_Exe()
CommandLine = "C:\Program Files\Mircosoft Office\Office\Winword.exe"
ErrCode = ExecCmd(CommandLine)
If ErrCode <> 0 Then
Call WhatError
Exit Sub
End If
End Sub
Sub WhatError()
'Here you can insert the error handling of the called program
End Sub
Greetz Scand
-
Apr 19th, 2000, 05:27 PM
#7
Member
Why does this forum doesn't accept tabs?
Greetz
Scand
-
Apr 19th, 2000, 05:32 PM
#8
Fanatic Member
Scand,
You can use vB code on this web site (similar to html). click on the (vB Code) link and it will exaplain all.
just to get you started you can use the tags. Just place any code them
['code']
'code goes here.
['/code']
Obviously you don't use the " ' " character, they are just there to stop the forum thinking i am placing code.
Iain, thats with an i by the way!
-
Apr 19th, 2000, 06:19 PM
#9
Member
Thanks, now all is clearly.
Try:
Code:
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 TypePrivate Type PROCESS_INFORMATION hProcess As Long hThread As Long
dwProcessID As Long dwThreadID As LongEnd TypePrivate CommandLine As String
Private ErrCode As Long
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 Long, 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 Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As
Long, _ lpExitCode As Long) As LongPrivate Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&Public Function ExecCmd(cmdline$) As Long
Dim proc As PROCESS_INFORMATION Dim start As STARTUPINFO
Dim ReturnValue As Integer ' Initialize the STARTUPINFO structure:
start.cb = Len(start) ' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish: Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0) DoEvents
Loop Until ReturnValue <> 258
ReturnValue = GetExitCodeProcess(proc.hProcess, ExecCmd)
ReturnValue = CloseHandle(proc.hProcess)End FunctionSub Start_Exe()
CommandLine = "C:\Program Files\Mircosoft Office\Office\Winword.exe"
ErrCode = ExecCmd(CommandLine) If ErrCode <> 0 Then Call WhatError Exit Sub
End IfEnd SubSub WhatError()
'Here you can insert the error handling of the called programEnd Sub
Greetz Scand
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|