Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Return focus from modeless UserForm?

20 views
Skip to first unread message

Chris Johnson

unread,
Feb 26, 2003, 4:06:21 PM2/26/03
to
First time posting here, so I hope this hasn't been
answered previously. Unfortunately, my search turned up
zero on this topic.

I'm writing with Word 2000/VBA, and want to have a
modeless UserForm A floating over the document at all
times, accessible for the user. However, when I call
other UserForms (B or C), the first modeless UserForm A
disappears.

Therefore, I wrote code so when user finishes with B or
C, the code calls a .Show function for the original
UserForm A to put it back over the document. In other
words, I want the modeless UserForm to be put back over
the document, but make it transparent to the user, who is
working in the document itself.

** Is there a way to programatically pass the Focus back
to the main Word document after calling a modeless
UserForm? **

Thanks for any tips you can offer.

Chris Johnson
Arete Clinical Systems

Perry

unread,
Feb 27, 2003, 5:03:47 PM2/27/03
to
Hi Chris,

Provided the Userform is called from the document interface
you can use below simple API calls to do it for you.

Declare Function GetActiveWindow Lib _
"user32" () As Long
Declare Function SetFocus Lib _
"user32" (ByVal hwnd As Long) As Long

Sub ShowForm()
Dim l As Long

'get window handle
l& = GetActiveWindow()
'show the modeless userform
UserForm1.Show 0
'return handle
SetFocus l&
End Sub

Krgrds,
Perry

"Chris Johnson" <cdjo...@pol.net> schreef in bericht
news:02c401c2ddda$ea09e040$a101...@phx.gbl...

0 new messages