ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Returning User Control to Excel from other Application in VBA (https://www.excelbanter.com/excel-programming/355719-returning-user-control-excel-other-application-vba.html)

[email protected]

Returning User Control to Excel from other Application in VBA
 
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!


AA2e72E

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!




All times are GMT +1. The time now is 01:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com