View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
AA2e72E AA2e72E is offline
external usenet poster
 
Posts: 400
Default Returning User Control to Excel from other Application in VBA

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.

" wrote:

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!