View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How do I switch focus from a modeless user form back to the excel.

Sub Tester3()
Mainform.Show vbModeless
With Mainform 'the modeless userform
.Height = 32
.Width = 40
.Left = 30
.Top = 30
End With

AppActivate Application.Caption

End Sub
Sub Tester4()
With Mainform 'the modeless userform
.Height = 32
.Width = 40
.Left = 30
.Top = 30
End With

AppActivate Application.Caption
End Sub

both worked fine for me.

--
Regards,
Tom Ogilvy

"RB Smissaert" wrote in message
...
I found that that doesn't always work.
For example:

With MainForm 'the modeless userform
.Height = 32
.Width = 40
.Left = 30
.Top = 30
End With

AppActivate Application.Caption

It looks as if Excel has the focus, but for example pressing the arrow

keys
doesn't change the selected cell.


RBS



"Tom Ogilvy" wrote in message
...
Anoter possibility is to use appactivate:

An example:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$C$3" Then
UserForm1.Show vbModeless
AppActivate Application.Caption
End If
End Sub


--
Regards,
Tom Ogilvy



"Yoam69" wrote in message
...
When I call a modeless user form, I want to then switch the focus back

to
the
excel window that was active when the form was called, but leave the

form
active (but not with the focus). Nothing I've tried has worked so far.