View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Set focus on controls of modeless form

Userforms do not expose a 'GotFocus' event, which is not the same as the
Userform's VBA Activate event.

Simplest approach would be with an OntIme macro to check which window is
currently active, which you can get with the GetForegroundWindow API.

If you need to know more accurately when user activates Excel or Userform,
or some other window (actually just beforehand), a low level hook along the
lines of the 'CBTProc Function' as demonstrated to you in one of your other
threads would keep you informed. Overkill I would have thought though for
this objective alone.

Regards,
Peter T


"Robert Crandal" wrote in message
...
Hi OssieMac,

The code below works, but it assumes that the user will click somewhere
WITHIN the userform. If the user clicks on the top title bar to
re-activate the userform that code will not work.

How can I detect if the form is activated by a click on the top title
bar??


"OssieMac" wrote in message
...
Hi Robert,

I don't know why the following works. I suspect some kind of bug but use
the
userform click event and then set the focus to another control first then
to
the one you really want.

Private Sub UserForm_Click()
Me.TextBox2.SetFocus
Me.TextBox1.SetFocus
End Sub

--
Regards,

OssieMac