Option Explicit
Private Declare Function GetFocus Lib "user32" () As Long
Dim a As LongPrivate Sub Timer1_Timer()
'得到焦点的窗口句柄
a = GetFocus
If Text1.hWnd = a Then
 MsgBox "焦点在TextBox1上"
ElseIf Text2.hWnd = a Then
 MsgBox "焦点在TextBox2上"
ElseIf Text3.hWnd = a Then
 MsgBox "焦点在TextBox3上"
End If
End Sub

解决方案 »

  1.   

    我没用timer而是用command按钮做的。用鼠标定位文本框,然后按command按钮,得出句柄,但是值都不对。用timer得的值就对,为什么????
      

  2.   

    select case  Screen.ActiveControl.Name
    case "Text1"
       MsgBox "焦点在TextBox1上"
    case "Text2"
       MsgBox "焦点在TextBox2上"case "Text3"
       MsgBox "焦点在TextBox3上"end select
      

  3.   

    点commandbutton后,焦点就到它上面去了