Sub SelectAll(TheControl As TextBox)
  TheControl.SelStart = 1
  TheControl.SelLength = Len(TheControl)
  TheControl.SetFocus
End SubPrivate Sub Text1_GotFocus()
  SelectAll (Text1)
End Sub
//功能很简单,就是让text得到焦点时全选取text1.text

解决方案 »

  1.   

    Private Sub Text1_GotFocus()
        SendKeys "{HOME}" + "+{END}"
    End Sub
      

  2.   

    不要加括号
    SelectAll Text1
      

  3.   

    Sub SelectAll(TheControl As TextBox)
      TheControl.SelStart = 0
      TheControl.SelLength = Len(TheControl)
      TheControl.SetFocus
    End SubPrivate Sub Text1_GotFocus()
      SelectAll Text1
    End Sub
      

  4.   

    Sub SelectAll(TheControl As TextBox)
      TheControl.SelStart = 0 '这个应该从零开始,而不是1
      TheControl.SelLength = Len(TheControl)
      TheControl.SetFocus
    End SubPrivate Sub Text1_GotFocus()
      Call SelectAll(Text1) '调用的时候如果没有返回值,可以不用括号,或者用CALL
    End Sub
      

  5.   

    Sub SelectAll(TheControl As TextBox)
      TheControl.SelStart = 0
      TheControl.SelLength = Len(TheControl)
      TheControl.SetFocus
    End SubPrivate Sub Text1_GotFocus()
      SelectAll (Me.Controls("text1"))
    End Sub
      

  6.   

    TextBox的name有二义性
    如Name为Text1的TextBox:
    名字Text1也可等价于Text1.text——String类型数据
    当然也可作为控件名Text1——Controls对象型数据
      

  7.   

    Sub SelectAll(TheControl As TextBox)
     on error resume next
      TheControl.SetFocus
      TheControl.SelStart = 0
      TheControl.SelLength = Len(TheControl)
    End SubPrivate Sub Text1_GotFocus()
     call SelectAll (Text1)
    End Sub