help with command bar positioning

  • Thread starter Thread starter rogervand
  • Start date Start date
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
 
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
 
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
 

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

Back
Top