View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Paul Paul is offline
external usenet poster
 
Posts: 661
Default Set tabindex automatically

Peter,

Thanks for your reply,

I'm getting a 1004 error when running your code, any suggestions?

Cheers,

Paul.

"Peter T" wrote:

Try this -

Sub myTabOrder()
' dump control names to cells
' select re-sorted controls in tab index order high first
' change bDump True/false and form name to suit
Dim bDup As Boolean
Dim i As Long
Dim cel As Range
Dim ctr As Object

bDump = True ' read

With ThisWorkbook.VBProject.VBComponents("UserForm1").D esigner

If bDump Then ' read

For Each ctr In .Controls
' this order will always be the order
' controls were added to the form
i = i + 1
Cells(i, 1) = ctr.Name
Cells(i, 2) = ctr.TabIndex

Next
''''''''''''''''''''''
'' discard any controls whose container is not the form
'' eg in frames or page controls
'' Sort controls in order highest tabindex to lowest
'' note first tabindex is 0,
'' eg if nine controls in order is 8-0
'' Select cells with the control names
'''''''''''''''''''''''''''

Else
For Each cel In Selection
.Controls(cel.Value).TabIndex = 0
Next
End If
End With

End Sub


Regards,
Peter T
"Paul" wrote in message
...
Hi,

I've got a userform with a lot of textboxes, comboboxes etc. During
development there was a lot dragging those boxes all over the form, and
offcourse the tabindexes are now totally off!

Is there a way to, via a macro or something, to automatically set the
tabindexes the way I would like them?

Cheers,

Paul