限制只能输入中文
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
strText = TextBox1.Text
Length = 0
For i = 1 To Len(strText)
temp = Asc(Mid$(strText, i, 1)) '将每个字符转为ASCII码
If temp > 255 Or temp < 0 Then ‘ASCII码小于0或大于255则为中文字
TextBox1.Text = Left(strText, Length)
Else
Length = Length + 1
End If
Next i
End Sub
限制只能输入数字
Private Sub TextBox4_Change()
If Len(TextBox4) > 0 And Not IsNumeric(TextBox4.Value) Then
If Asc(TextBox4) <> 45 Then ’判断是否是负号
TextBox4.SetFocus
SendKeys "{BACKSPACE}"
End If
End If
End Sub
评论