How can you get a handle (hwnd) to the active form in VBA?

E

Eric Juvet

In VB6, the handle to the activeform is simply Me.hwnd or Form1.hwnd.

In VBA, "hwnd" is not a property. How can you get a handle to the active
form in VBA? Undoubtedly it would require a WinAPI call which I know how to
do.

- Eric Juvet
 
J

Jonathan West

Eric Juvet said:
In VB6, the handle to the activeform is simply Me.hwnd or Form1.hwnd.

In VBA, "hwnd" is not a property. How can you get a handle to the active
form in VBA? Undoubtedly it would require a WinAPI call which I know how to
do.

- Eric Juvet

Place the following code in your UserForm

Before the first routine, include the following

Public hWnd as Long
Private Declare Function GetActiveWindow Lib "user32" _
Alias "GetActiveWindow" () As Long

Then put the following code at the start of the UserForm_Activate event

hWnd = GetActiveWindow()

You can then use hWnd as a property of the UserForm
 

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