Activate UserForm with only one 'Enter'

前端 未结 2 933
忘掉有多难
忘掉有多难 2021-01-22 05:36

I want to start up the UserForm with ONLY pressing on a number and on Enter (so no clicking involved). The problem I have is with pressing Enter twice. What happens if I press E

2条回答
  •  再見小時候
    2021-01-22 06:34

    Ralph's solution is the easiest way to implement it if you have a simple form like yours

    If you have multiple buttons, or use labels instead of buttons you can do something like this

    Private Sub TxtBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    
        If KeyCode = vbKeyReturn Then Me.Hide    'or CommandButton1_Click
    
    End Sub
    

提交回复
热议问题