J
Jerett
I need some help with this.
I am trying to set the tab order in an excel worksheet using VBA. I
found the following code on one of the newsgroups:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Dim bBackwards As Boolean
Const ctlPrev As String = "G10"
Const ctlNext As String = "TextBox2"
Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
If Application.Version < 9 Then Sheet1.Range("A1").Select
If bBackwards Then
Range(ctlPrev).Activate
Else
ActiveSheet.OLEObjects(ctlNext).Activate
End If
Application.ScreenUpdating = True
End Select
End Sub
It works very well but I would have to put this in for each ole object
and cell pointing to an ole object. What I would rather do is pull an
array from an excel worksheet and use a routine to handle this. This
would make the tab order a little more controllable and would use a
lot less code, I have about 100 textboxes, checkboxes, option buttons,
and dropdowns on the worksheet.. I think that I would need to put the
property type in as a variable as well so I would have to specify in
the array whether the item is a Range or OLEObject. As you can see
from the example above I modified the original code that I found to
point to a cell instead of another OLEObject.
And just one more question: Why did Microsoft make this so difficult.
Seems like it should be an easy problem.
I am trying to set the tab order in an excel worksheet using VBA. I
found the following code on one of the newsgroups:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Dim bBackwards As Boolean
Const ctlPrev As String = "G10"
Const ctlNext As String = "TextBox2"
Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
If Application.Version < 9 Then Sheet1.Range("A1").Select
If bBackwards Then
Range(ctlPrev).Activate
Else
ActiveSheet.OLEObjects(ctlNext).Activate
End If
Application.ScreenUpdating = True
End Select
End Sub
It works very well but I would have to put this in for each ole object
and cell pointing to an ole object. What I would rather do is pull an
array from an excel worksheet and use a routine to handle this. This
would make the tab order a little more controllable and would use a
lot less code, I have about 100 textboxes, checkboxes, option buttons,
and dropdowns on the worksheet.. I think that I would need to put the
property type in as a variable as well so I would have to specify in
the array whether the item is a Range or OLEObject. As you can see
from the example above I modified the original code that I found to
point to a cell instead of another OLEObject.
And just one more question: Why did Microsoft make this so difficult.
Seems like it should be an easy problem.