I'm building an Excel worksheet into a kind of dashboard with CommandButtons and TextBoxes to drive the functionality of the rest of the document.
I'm trying to recreate some of the functionality of a UserForm (e.g., tab order). I'm using the CommandButton's KeyDown event to respond if the user presses Enter:
Private Sub Button_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
Call Button_Click
ElseIf KeyCode = vbKeyTab Then
If (Shift And 1) > 0 Then
Me.PreviousButton.Activate
Else 'no shift
Me.NextButton.Activate
End If
End If
End Sub
The problem is the underlying worksheet also responds to the Enter keystroke (it scrolls down and I'm not sure what else it may be doing), even though it's protected from users selecting cells.
So how do I control this or intercept keystroke events when a control embedded in a worksheet is active? Is there another strategy I should be following? Any recommended resources?
Bookmarks