Command Bar position

M

Matt Jensen

Howdy
I want my command bar to be positioned what I can only think to call
"opposite to being floating".

Set MYCommandBar = CommandBars.Add(Name:="MyBar", _
Position:=msoBarFloating, Temporary:=True)

what is the oppositite to the above? Is it msoBarTop - where does that put
it relative to the other menus bars that are at the top? I want to add it
above the main window but below all other toolbars.
And what and when is the following code used for:
MenuBar:=True
?

Thanks
Matt
 
S

Sharad

Apart from msoBarFloating you can have
msoBarLeft
msoBarRight
msoBarTop
msoBarBottom

mosBarTop will put the command bar at the top just below the menubar.
(The topmost tool bar will be your commandbar).

If you set MenuBar:=True then the existing menubar (where you have File,
Edit, Instert etc. menus) will disappear and your command bar will take
its place if it is msoBarTop.

Sharad
 
M

Matt Jensen

Thanks Sharad
So how do I put my command bar above my worksheet window below the menubar
but below the other command bars there and without replacing any of the
command bars that are there?
Do I just omit the Position property?
Thanks
Matt
 
J

Jim Cone

Matt,

You need to provide the "RowIndex"...

MyCommandBar.RowIndex = Application.CommandBars("Formatting").RowIndex + 1

If the Formatting toolbar is visible, the above code places MyCommandBar
just below the formatting toolbar.
No, you cannot determine the rowindex by just counting the visible toolbars.
Also, you still need msoBarTop.

OR, go thru the CommandBar collection and find the largest rowindex...

Sub TestBar()
Dim MyCommandBar As CommandBar
Dim lngBarIndex As Long

For Each MyCommandBar In Application.CommandBars
If MyCommandBar.Visible Then lngBarIndex = _
WorksheetFunction.Max(lngBarIndex, MyCommandBar.RowIndex)
Next

Set MyCommandBar = CommandBars.Add(Name:="MyBar", _
Position:=msoBarTop, Temporary:=True)
MyCommandBar.RowIndex = lngBarIndex + 1
MyCommandBar.Visible = True
Set MyCommandBar = Nothing
End Sub


Regards,
Jim Cone
San Francisco, USA
 
J

Jim Cone

Matt,

Looks like there is an easier way, using msoBarRowLast...
'--------------------------
Sub TestBarModified()
Dim MyCommandBar As CommandBar

Set MyCommandBar = CommandBars.Add(Name:="MyBar", _
Position:=msoBarTop, Temporary:=True)

MyCommandBar.RowIndex = msoBarRowLast

MyCommandBar.Visible = True
Set MyCommandBar = Nothing
End Sub
'--------------------------

Regards,
Jim Cone
 
S

Sharad

What do you mean by "Looks Like" Jim?

That's not only the easiest, but the 'Accurately Correct' way! :)

Thanks for me too (Apart from Matt will be thankful)
cheers!

Sharad
 

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