Returning User Control to Excel from other Application in VBA

P

proteus815

Hi.

I'm using Excel VBA to control both Excel and another application.
However, there are times when I want to control whether Excel or the
other application is the 'active' application and the one displaying on
the screen. (I pop up a user form in Excel, but the user has to click
Excel in the windows toolbar to activate it before they see the form).

How do I return control back to Excel from the other application?

Thanks!
 
G

Guest

An API call may give you the control you seek:

Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

If you are using Excel 2003, hwnd is a property of the application object.
For the other application (and other versions of Excel), you need to find its
HWND property. If it is not an exposed property, use the API call FINDWINDOW:
it MAY give you its handle:

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

PS: the lpclassname for Excel parameter for ALL versions of Excel is XLMAIN.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top