如何才允许用户仅在字段中键入数字和退格?
Private Sub Field_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
End Sub
有了这个,用户也无法使用退格...
答案 0 :(得分:1)
答案 1 :(得分:0)
使用此:
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then KeyAscii = 0
答案 2 :(得分:0)
以下是两种方式
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub