Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default open and close another app from macro

I have used the following line of code to open another application
from an excel macro:

AppVal = Shell("C:\Program Files\SAP\saplogon.exe")

Is there something similar I can execute to close this application?




John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default open and close another app from macro

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



"John Keith" wrote:

I have used the following line of code to open another application
from an excel macro:

AppVal = Shell("C:\Program Files\SAP\saplogon.exe")

Is there something similar I can execute to close this application?




John Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default 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



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
Open , Save, and Close Macro [email protected] Excel Programming 1 December 13th 07 03:41 PM
VBA Project - Open/Close with Macro Danny Excel Worksheet Functions 2 September 7th 07 11:02 PM
macro to run on first open after save and close pswanie Excel Programming 2 June 17th 07 07:44 PM
Macro to run automatically on Open/Close Sarah (OGI) Excel Programming 2 March 28th 07 04:02 PM
run macro on close & open Stu[_27_] Excel Programming 3 October 15th 03 02:09 PM


All times are GMT +1. The time now is 03:41 PM.

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

About Us

"It's about Microsoft Excel"