KeyPress事件不会打印最后输入的字符

时间:2018-01-27 03:14:22

标签: vba excel-vba ascii excel

打印在文本框中输入的字符时,始终省略最后一个字符。尝试使用KeyUp事件,但它会在每次输入时触发Case Else。有什么想法吗?

Private Sub hoursOverBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case KeyAscii
    Case 46, 48 To 57
    Case Else
        KeyAscii = 0
        MsgBox "Only numbers allowed!"
End Select
Me.hoursOverBox.MaxLength = 5
On Error Resume Next
hoursOver = Me.hoursOverBox.value
End Sub

1 个答案:

答案 0 :(得分:0)

更改此行:

 ByVal KeyAscii As MSForms.ReturnInteger

ByVal KeyAscii As Integer