Subscript out of range error?

S

salgud

I'm not too familar with this error, and new to working with toolbars in
VBA, so I'm lost on even what to look for on this error. The code so far
is:

Option Explicit
Public Const runCreatetribalTR As String = "RunCreateTribalTR"

Sub Auto_Open()
Call CreateMenubar
With CommandBars("CreateTR")
.Enabled = False
.Visible = False
End With

End Sub

Sub Auto_Close()
Call RemoveMenubar
End Sub

Sub RemoveMenubar()
On Error Resume Next
Application.CommandBars(runCreatetribalTR).Delete
On Error GoTo 0
End Sub

Sub CreateMenubar()

Call RemoveMenubar

With Application.CommandBars.Add
.Name = runCreatetribalTR
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarTop
.Left = CommandBars("RunCreateTribalTR").Left +
CommandBars("RunCreateTribalTR").Width
.RowIndex = CommandBars("RunCreateTribalTR").RowIndex

With
CommandBars("RunCreateTribalTR").Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "CreateTR"
.Caption = "CreateTR"
.Style = msoButtonCaption
.TooltipText = "Create TR"
End With

' With
CommandBars("RunCreateTribalTR").Controls.Add(Type:=msoControlButton)
' .OnAction = "'" & ThisWorkbook.Name & "'!" & "MergeCells"
' .Caption = "Merge Cells"
' .Style = msoButtonCaption
' .TooltipText = "Merge/Unmerge Cells"
' .BeginGroup = True
' End With
With
CommandBars("RunCreateTribalTR").Controls.Add(Type:=msoControlButton, ID _
:=2950, Before:=3) <----SUBSCRIPT OUT OF RANGE
End With
End With
End Sub


Public Sub CreateTR()
Call CreateTribalSheet
End Sub

I've marked the error line above.
Can anyone please help me here?
Thanks!
 
P

Per Jessen

As you have commented out the Merge/UnMerge control there is only one
control in the new CommandBar.

Change the problem line from :
...Before:=3
to
...Before:=2

Regads,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top