View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Shell can open an application, can it close an app too?

No, Shell cannot close the app. You will need to do it another way. The
simplest way is probably to use SendKeys to send the proper command to close
the app; most often this would be Alt-F to get the file menu and then X to
Exit. Or Alt-F4 often closes the app. But SendKeys can be tricky since you
need to make sure you know exactly the state the other application is in to
know that the key combination will do what you want it to do, and also in
rare occasions I have had other apps grab focus before SendKeys can act (e.g.
I get an email notification from Groupwise between the AppActivate and
SendKeys commands), which then sends the keys to the wrong application with
potentially disasterous results. In other words, use the following code with
discretion and test it under a variety of conditions.

The code would be:

AppActivate "AppTitleBarText"
' AppTitleBarText is the exact text in the title bar of the application you
want activated
' Note: You can use the TaskID returned by Shell instead of the title bar text
SendKeys "%FX", True
' Sends the keys specified to the activae application - this is AltF and X

"quartz" wrote:

I am using Office 2003 on Windows XP.

I use Shell to open foreign apps like Acrobat and MODI, but can Shell (or
some other command) be used to close these applications as well? If so, how?

Could someone please post example code? Thanks much in advance.