![]() |
open and close another app from macro
|
open and close another app from macro
On Sun, 13 Sep 2009 00:11:01 -0700, Joel
wrote: the shell function returns a handle. the TerminateProcess uses a handle to kill the process. You just have to declare the definiation of the TerminateProcess function outside a routine like th code below. Private Declare Function TerminateProcess Lib "kernel32" _ (ByVal hProcess As Long, _ ByVal uExitCode As Long) As Long Sub Terminate() AppVal = Shell("C:\Program Files\SAP\saplogon.exe") lRetValue = TerminateProcess(AppVal, 0&) End Sub Thank you Joel, I'll do some more study as this opens some new territory for me. John Keith |
open and close another app from macro
The handle of a window is the Process ID. Every window has a handle which in
VBA is HWND. To get a window you can use the parent of the window like this handle = thisworkbook.parent.hwnd You can also activate the window using either the title of the Window or the process number AppActivate title (or handle) like this AppActivate "Book1.xls" Then you can get the handle from the activewindow AppActivate "Book1" Handle = ActiveWindow.Application.Hwnd You can also use any Win32 dll to get the process number. "John Keith" wrote: On Sun, 13 Sep 2009 00:11:01 -0700, Joel wrote: the shell function returns a handle. the TerminateProcess uses a handle to kill the process. You just have to declare the definiation of the TerminateProcess function outside a routine like th code below. Private Declare Function TerminateProcess Lib "kernel32" _ (ByVal hProcess As Long, _ ByVal uExitCode As Long) As Long Sub Terminate() AppVal = Shell("C:\Program Files\SAP\saplogon.exe") lRetValue = TerminateProcess(AppVal, 0&) End Sub Thank you Joel, I'll do some more study as this opens some new territory for me. John Keith |
open and close another app from macro
On Sun, 13 Sep 2009 04:29:01 -0700, Joel
wrote: The handle of a window is the Process ID. Every window has a handle which in VBA is HWND. To get a window you can use the parent of the window like this handle = thisworkbook.parent.hwnd Joel, Thank you for even further detail! (I get so frustrated trying to find good VBA documentation!) John Keith |
All times are GMT +1. The time now is 09:06 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com