help with command bar positioning

R

rogervand

I have been successful in creating a custom commandbar with the button
I need. I would like to place the custom commandbar on the end of th
built in commandbars at the top of my window. I can get it up there
but it seems to want to live on a line all by itself. I've been usin
the following command:

commandbars("custom").rowindex = 2

It puts my bar where I want it, but moves the builtins down a row. An
advice out there?

Thanks,
Roge
 
B

Bernie Deitrick

Roger,

You need to se the .Left and .RowIndex of your new commandbar based on an
existing commandbar. See the code example below.

HTH,
Bernie
MS Excel MVP

Sub AddSecondCommandbarAfterFirst()
Dim myBar1 As CommandBar
Dim myBar2 As CommandBar

On Error Resume Next
Application.CommandBars("NewCBName").Delete

Set myBar1 = Application.CommandBars("OldCBName")
Set myBar2 = Application.CommandBars.Add("NewCBName")

With myBar2
Set myButton = myBar.Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "This or that"
.Style = msoButtonIcon
.FaceId = 137
End With
.Position = msoBarTop
.Left = myBar1.Width
.RowIndex = myBar1.RowIndex
.Visible = True
.Enabled = True
End With

End Sub
 
R

rogervand

Thanks for the help Bernie. I stumbled across the solution a few minute
after posting. I was able to set the position relative to th
"Standard" command bar
 
Top