View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
ZABU ZABU is offline
external usenet poster
 
Posts: 12
Default Peter Huang, Vasant, Chip Pearson - Close External Application VBA - ZABU

I was able to download a copy of Spy++ and another program called
Winspector that allowed me to obtain the class of the window. Thanks for
all of the input!! However I have an additional question. The external
application opens(primary window of one class name) and performs a data
search (in a sub window of a different class name) and transfers the
retrieved data to excel. Following the data transfer to excel, the sub
window is closed, leaving only the primary window, which I can now close
using Chips code.

Question is this:

Can I monitor the sub window as a trigger to initiate the Close Window Sub
and then launch another search? Reason is this, once the data has been
transferred to excel and the window is closed that search is complete. The
time for each search (30 or more searches in the routine) will vary
depending on the amount of data retrieved.

The Shell and Wait sub will start the external program search, but I believe
that as long as the primary window of the application is open, the macro
will continue to wait, even after the data has been transferred, which is
not desirable.

Currently the Sell command is used to perform a data search and a wait
function is set at 10 seconds, then performs the task again, with each
search opening another window of the search application.

Any information is greatly appreciated!

Thanks in advance

Regards,

ZABU

"Tom Ogilvy" wrote in message
...
This article should get you going on finding the information you need:


http://support.microsoft.com/default...b;en-us;147659
HOWTO: Get a Window Handle Without Specifying an Exact Title

(in case you don't have spy++ from visual studio)

--
Regards,
Tom Ogilvy


"ZABU" wrote in message
...
That is correct. I do not know the correct class name and am not

completely
sure of the window name - unless that is the text in teh title bar of

the
window. The window does not respond to the sent message to close. And
further, I am not sure what exit code the window I am trying to close

will
accept. Do you have any tools that will give the class knowing the

title
of
the window and how to determine the exit code?

Thanks in advance!

ZABU
"Chip Pearson" wrote in message
...
Zabu,

What specific problems are you having? Are you sure that you are
using the correct class name and window name for the call to
FindWindow (use Spy++ to find out the proper values)? Does the
window not respond to the sent messages?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"ZABU" wrote in message
...
Peter, Vasant or Chip:

I have finally tested the code discussed in prior posts
regarding closing an
external application with VBA Code. I have successfully
executed the "Send
and Wait" command for the "Calc.exe" Test use of API calls and
monitoring.
Once the program is clsoed a message appears, which
communicates that the
program has been closed.

I am currently at the following step and am having diffuculty.
I need to
find a particular window and close the application associated
with the
window after a search and data transfer to excel (this will
occur about 30
times, so this many windows will have to be closed). I have
reviewed the
following code from Chip Pearson (I believe), but am having
difficulty. I
believe that I need to find the specific classname and window
name
associated with the "FindWindowA" function. This is shown in
the code below,
but I cannot get it to execute. Please send any informatin
that may assist
in my efforts. Example code will be very useful! Many thanks
in advance!

Kind Regards,

ZABU


Code located on the Google Groups:

Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" _
(ByVal HWnd As Long, ByVal wMsg As Long, ByVal wParam As
Long, lParam As
Any) As Long
Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
As Long

Public Const WM_CLOSE = &H10
Public Const WM_DESTROY = &H2
Public Const WM_NCDESTROY = &H82


Sub CloseWindow()
Dim HWnd As Long
'Dim lpClassName As String
'Dim lpWindowName As String

HWnd = FindWindow("CabinetWclass", "Baytek WinBLISS")
If HWnd 0 Then
SendMessage HWnd, WM_NCDESTROY, 0, 0
End If
End Sub