Excel Vba:在任何键击/按下运行macros

我正在使用下面的vba代码来运行enter键按下事件的macros。 然而,有没有办法我可以改变这个代码运行任何击键不只是input?

这里是我使用的代码:

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii = 13 Then MsgBox "You Pressed a key" End If End Sub 

提前致谢

由于KeyAscii总是正面的 ,请尝试:

 Private Sub TextBox2_KeyPress(KeyAscii As Integer) If KeyAscii > -1 Then MsgBox "You Pressed a key" End If End Sub 

此外,我刚刚检查过,您必须删除As MSForms.Returninteger部分。 我刚刚发布的代码对我来说工作得非常好。