ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Linking the ENTER key to a Button on a Form? (https://www.excelbanter.com/excel-programming/391197-linking-enter-key-button-form.html)

Jason Paris[_2_]

Linking the ENTER key to a Button on a Form?
 
Hi folks,

I'm creating a User Form in Excel. It includes a Text Box and a
number of buttons.

When the user types into the Text Box and (instinctively) presses
ENTER, is there a way to simulate the clicking of a button? In other
words, can ENTER - when pressed from the Text Box - be used to trigger
the code behind a button?

Many thanks,

Jason Paris


tissot.emmanuel

Linking the ENTER key to a Button on a Form?
 
Hi,

Your textbox name is TextBox1, your button name is btnOK:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Then btnOK_Click
End Sub

Private Sub btnOK_Click()
MsgBox "OK launched by ENTER"
End Sub

Regards,

Manu/

"Jason Paris" a écrit dans le message de news:
...
Hi folks,

I'm creating a User Form in Excel. It includes a Text Box and a
number of buttons.

When the user types into the Text Box and (instinctively) presses
ENTER, is there a way to simulate the clicking of a button? In other
words, can ENTER - when pressed from the Text Box - be used to trigger
the code behind a button?

Many thanks,

Jason Paris





All times are GMT +1. The time now is 01:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com