Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to close external program from Word/Excel 97 VBA?

109 views
Skip to first unread message

Efim Shvartsburg

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
I know how to open external program from VBA using
Shell(pathname[,windowstyle])

But how I can close it?

Laurent Longre

unread,
Jan 20, 1999, 3:00:00 AM1/20/99
to Efim Shvartsburg
Hi Efim,

Efim Shvartsburg a écrit :


>
> I know how to open external program from VBA using
> Shell(pathname[,windowstyle])
> But how I can close it?

You can use API calls to do this. For instance, the following code opens
Winmine.exe (one of my preferred Wingames: 142 seconds at expert level
;-), and then closes it by using TerminateProcess.

Tested only in Win95 :

Declare Function OpenProcess Lib "Kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Declare Function GetExitCodeProcess Lib "Kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long

Declare Function TerminateProcess Lib "Kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Sub Test()

Dim ProcessHandle As Long
Dim ProcessId As Long
Dim ExitCode As Long

' Launch a new instance of WinMine.exe
ProcessId = Shell("Winmine.exe", vbMinimizedNoFocus)
ProcessHandle = OpenProcess(&H1F0000, 0, ProcessId)
GetExitCodeProcess ProcessHandle, ExitCode

' Close WinMine
MsgBox "Ready to close WinMine?", vbOKOnly
TerminateProcess ProcessHandle, ExitCode

End Sub


HTH,

Laurent

Patrick Molloy

unread,
Jan 20, 1999, 3:00:00 AM1/20/99
to
HA . 124 my best !

Patrick
______
Laurent Longre wrote in message <36A528DF...@wanadoo.fr>...

Laurent Longre

unread,
Jan 20, 1999, 3:00:00 AM1/20/99
to

Congratulations!

Laurent

Patrick Molloy a écrit :

0 new messages