Tab to an Activex Worksheet Control

MSingh
3StarLounger
Posts: 366
Joined: 12 May 2010, 06:49

Tab to an Activex Worksheet Control

Post by MSingh »

Hi,

How can i set the tab order for worksheet activex controls as one would in a userform?

Thanks
Mohamed

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Tab to an Activex Worksheet Control

Post by HansV »

ActiveX controls on a worksheet don't have a tab order, so you have to write VBA code for the On Key Down event of each and every control, e.g.

Code: Select all

Private Sub CheckBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyTab Then
        KeyCode = 0
        Me.TextBox2.Activate
    End If
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyTab Then
        KeyCode = 0
        Me.CheckBox1.Activate
    End If
End Sub

Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyTab Then
        KeyCode = 0
        Me.TextBox1.Activate
    End If
End Sub
In this example, the Tab key will cycle from TextBox1 to CheckBox1 to TextBox2 and back to TextBox1.
Best wishes,
Hans

MSingh
3StarLounger
Posts: 366
Joined: 12 May 2010, 06:49

Re: Tab to an Activex Worksheet Control

Post by MSingh »

Thanks again Hans for the instant reply.

Kind Regards
Mohamed