If Len(Trim$(txtBdno.Text)) = 4 Then
   If IsNumeric(txtBdno.Text) = True Then
      txtBdno.Text = txtBdno.Text & "年"   Else
      txtBdno.SetFocus
      txtBdno.SelStart = 0
      txtBdno.SelLength = Len(Trim$(txtBdno.Text))
      strMes = "请输入数字!"
      MsgBox strMes, , "提示!"
   End If
End If
我想在输入四个数字后自动添加一个"年"
就是我输入 2001后自动变成  2001年 并将光标放到字符串后面继续输入?
即 2001年 后面
该怎么办?

解决方案 »

  1.   

    执行完text后.
    sendkeys "{End}"
      

  2.   

    txtBdno.SetFocus
    txtBdno.SelStart = Len(Text1.Text)
      

  3.   

    这样就可以了
    Option ExplicitDim i As String
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    If Len(Trim$(Text1.Text)) = 4 Then
       If IsNumeric(Text1.Text) = True Then
          i = i + Text1.Text & "年"
          Print i
       Else
          Text1.Text = ""
          Text1.SetFocus
          
       End If
    End If
    End If
    End Sub