[RESOLVED] How to use keypress in Excel VBA
hi everyone,
I have a problem in using keypress event in excel. i have this code but it doesn't work. What i want to do is after I input a value in the textbox and press then Enter key the Commandbutton2_click will activate. Can anyone help me.
Thanks and Regards,
Kevin
Code:
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 13 Then
CommandButton2_Click
End If
End Sub
Re: How to use keypress in Excel VBA
enterkeys are not trappable in keypress event in msforms2 textboxes, use keydown or keyup event
vb Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
CommandButton1_Click
End If
End Sub
Re: How to use keypress in Excel VBA
Hi pete,
Your code works!! :) thanks!! now my only problem is how to trap if the user inputs an incorrect password. im still trying to figure out.