Barry,
This works perfectly for me (Word 97)
For Each cmd In CommandBars
If cmd.Name = "BarryToolbar" Then
CommandBars("BarryToolbar"
CommandBars("BarryToolbar"
Exit Sub
End If
Next
Main Topics
Browse All TopicsI've added a macro to a Word template, and have the following code in place to access it:
==== BEGIN PASTE ====
Sub AutoNew()
Dim myBar As CommandBar
Dim myControl As CommandBarButton
Dim cmd As CommandBar
For Each cmd In CommandBars
If cmd.name = "BarryToolbar" Then
CommandBars("BarryToolbar"
Exit Sub
End If
Next
Set myBar = CommandBars.Add( _
name:="BarryToolbar", _
Position:=msoBarPopup, _
menubar:=True, _
Temporary:=True)
Set myControl = CommandBars("BarryToolbar"
Type:=msoControlButton, _
Before:=1)
With myControl
.OnAction = "SubroutineToCall"
.FaceId = 0
.Caption = "Perform Barry's Action"
.TooltipText = "Click the button to perform Barry's action"
.DescriptionText = "PerformBarry'sAction"
.Style = msoButtonCaption
End With
CommandBars("BarryToolbar"
End Sub
===== END PASTE =====
This does a great job of creating a floating toolbar with one button on it, and the button works great when clicked. But if the first thing the user does is close the floating toolbar to get it out of the way, they have to know to go to the View -> Toolbars menu to get it back. Many of my users aren't that quick.
What can I do to get the toolbar to appear not as a floater, but docked, up with the other docked toolbars, at the top?
I've tried setting the myBar.Position to msoBarTop (and left, and bottom, and right), but nothing seems to change where it appears -- as a floater somewhere over my document.
Any assistance would be most appreciated.
-- b.r.t.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Aaaargh!
This has been infuriating for me, because nothing seems to be consistent.
Apparently the position and visibility of that toolbar had gotten into my Normal.dot, so none of my changes were showing. I've renamed my Normal.dot out of the way to prevent that.
Now I'm trying all kinds of stuff as hybrids of your suggestions, but every time I get my toolbar to appear at either the top or bottom of the screen, my menu bar disappears!
This is my current code. Note that I've tried to set the RowIndex in two places, and it doesn't seem to make the difference. Also, I've set the position to msoBarTop. This causes the same problem with the position set to msoBarBottom, msoBarLeft, or msoBarRight.
I've also tried variations where I didn't set the RowIndex, with the same luck. Every time I've been able to get my toolbar to appear docked, the menu bar disappears.
I can get the toolbar to appear as a floater, and drag it up. But that's not doing it for me.
Any ideas?
==== BEGIN PASTE ====
Sub AutoNew()
Dim myBar As CommandBar
Dim myControl As CommandBarButton
Dim cmd As CommandBar
Dim intMenuRow as Integer
For Each cmd In CommandBars
If cmd.Name = "Menu Bar" Then intMenuRow = cmd.RowIndex
Next
For Each cmd In CommandBars
If cmd.name = "BarryToolbar" Then
CommandBars("BarryToolbar"
cmd.RowIndex = intMenuRow + 1
Exit Sub
End If
Next
Set myBar = CommandBars.Add( _
name:="BarryToolbar", _
Position:=msoBarTop, _
menubar:=True, _
Temporary:=True)
myBar.RowIndex = intMenuRow + 1
Set myControl = CommandBars("BarryToolbar"
Type:=msoControlButton, _
Before:=1)
With myControl
.OnAction = "SubroutineToCall"
.FaceId = 0
.Caption = "Perform Barry's Action"
.TooltipText = "Click the button to perform Barry's action"
.DescriptionText = "PerformBarry'sAction"
.Style = msoButtonCaption
End With
CommandBars("BarryToolbar"
End Sub
===== END PASTE =====
-- b.r.t.
But it does!
I've also tried it with a msgbox in there, as such:
==== BEGIN PASTE ====
For Each cmd In CommandBars
If cmd.Name = "Menu Bar" Then
intMenuRow = cmd.RowIndex
Msgbox cmd.Name
End If
Next
===== END PASTE =====
I'm getting that messagebox, so it is finding it.
I've also tried setting the RowIndex to msoBarRowLast, with no better luck. Then the toolbar is at the bottom of the stacka t the top of the window, but the menu bar still disappears.
I'm stumped.
Hi, Barry.
Some of this code is Private Sub Document_New()
Dim Mybar As CommandBar
Dim cmd As CommandBarPopup
Dim i As Integer
Dim A(4) As Variant
CustomizationContext = ActiveDocument.AttachedTem
On Error Resume Next
'Just making a dummy check to create error if menu exists
CommandBars("Menu Bar").Controls("A&nswers")
If Not Err.Number = 0 Then
A(1) = Array("Do this...", "DoThis", 71)
A(2) = Array("Do that...", "DoThat", 72)
A(3) = Array("Do the other...", "DoTheOther", 73)
A(4) = Array("Do nothing...", "DoNothing", 74)
With CommandBars("Menu Bar").Controls
.Add(Type:=msoControlPopup
End With
For i = 1 To UBound(A)
With CommandBars("Menu Bar").Controls("Answers").
Set myButton = .Add(Type:=msoControlButto
With myButton
.Caption = A(i)(0)
.OnAction = A(i)(1)
.FaceId = A(i)(2)
End With
End With
Next i
Else
End If
End Sub
<<<Insert your four macros here>>>
Private Sub Document_Close()
On Error Resume Next
ThisDocument.Saved = True
End Sub
And this is all pasted into a Word TEMPLATE (dot file).
You need to change this line:
>Dim A(4) As Variant
So that the number behind the A is the number of menu choices you have.
These lines:
>A(1) = Array("Do this...", "DoThis", 71)
Define each macro as ("Menu choice text","MacroName,Button Face ID)
I got the cool Button Face ID Add-In from John Walkenbach's site:
http://j-walk.com/ss/excel
And all credit for this answer should really go to smozgur, who wrote this code in a previous Q.
If this works for you, please post points for smozgur and ask community support to just PAQ the question.
:)
Now, after typing all the above, I realize you only needed to anchor the toolbar, and my code creates a menu. Never the less...I figure I'll leave it anyway in case you decide it doesn't need it's own toolbar but that a menu will do, and maybe someone else can use it.
~Dreamboat
www.TheWordExpert.com
Barry,
You never told that your new CommandBar was a Menubar, as indicated in this part of code:
Set myBar = CommandBars.Add( _
name:="BarryToolbar", _
Position:=msoBarTop, _
menubar:=True, _
Temporary:=True)
Excerpts from Word help on CommmandBars.add
"MenuBar Optional Variant. True to replace the active menu bar with the new command bar. The default value is False."
D'oh! I didn't know the CommandBar was a Menubar.
I've cobbled this code together from a variety of things I've found online, and made changes here and there as I tried to get things to work. I don't specifically recall changing (or even including, for that matter) that line, but obviously I'm guilty of something.
In any case, when I changed True to False, it worked exactly as one would hope. What a concept.
Regardless, bruintje and Dreamboat should look for separate points postings, just for being so helpful.
Thanks again to all who helped!
bruintje --
I've been a member for over two and a half years, and I've still got 1,100 points unspent. And maybe this way you'll still be quick to add commentary to expand on someone else's answer, even knowing they'll probably get the bulk of the points. The way I see it, the more input I get the better off I am. And since I'm not paying for these points...
Business Accounts
Answer for Membership
by: bruintjePosted on 2002-08-20 at 15:28:44ID: 7232188
Hello BarryTice,
f00006.htm
not sure but maybe this sample will help
http://www.mvps.org/skp/of
using the row index of the commandbars property
HAGD:O)Bruintje