Option Explicit
Private MeHWnd As Variant
'-------------------
'Activation UserForm
'-------------------
Private Sub UserForm_Activate()
MeHWnd = ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") 'handle fenetre active
Me.TextBox1.SetFocus
End Sub
'----------------------
'Survol souris UserForm
'----------------------
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim Ctrl As Variant
If MeHWnd <> ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") Then
Me.Show vbModeless
Set Ctrl = Me.ActiveControl
CreateObject("wscript.shell").SendKeys ("{TAB}")
DoEvents 'SendKeys synchrone
Ctrl.SetFocus
If TypeOf Ctrl Is TextBox Then
Ctrl.SelStart = Len(Ctrl.Value)
End If
End If
End Sub