EnterKey to press button in VBA Userform

后端 未结 6 953
春和景丽
春和景丽 2020-12-31 04:45

I have a userform in Excel that asks for a username and password. Once you enter your password if you press Enter it just \"selects\" the next item which is the <

6条回答
  •  别那么骄傲
    2020-12-31 05:29

    You could also use the TextBox's On Key Press event handler:

    'Keycode for "Enter" is 13
    Private Sub TextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = 13 Then
             Logincode_Click
        End If
    End Sub
    

    Textbox1 is an example. Make sure you choose the textbox you want to refer to and also Logincode_Click is an example sub which you call (run) with this code. Make sure you refer to your preferred sub

提交回复
热议问题