Be sure to avoid “magic numbers” whenever possible, either by defining your own constants, or using the vbXXX built-in constants.
In this case, we could use vbKeyReturn to specify the key of the input key (replacing YourInputControl and SubToBeCalled).
Private Sub YourInputControl_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = vbKeyReturn Then SubToBeCalled End If End Sub
This prevents a whole category of compatibility issues and simple typos, especially because VBA capitalizes identifiers for us.
Hooray!
drognisep
source share