Toolbars

C

C Holmes

I've got some weird things going on with a toolbar that I built in a word
document.

For some reason the toolbar is being displayed many times when the document
opens up. Yet to my knowledge the macro which builds the toolbar is not being
executed.

If I right click in the toolbar space at the top of Word (where you can see
the list of all toolbars) I can see a dozen or so instances of the toolbar.
If I go to the bottom of the list and click "Customize" I can delete all
instances of the toolbar and they then do not display. But the next time I go
to open up the Word document all instances of the toolbar again are
displayed. It's got me stumped.

It seems that the toolbar is saved with the word application and not the
document as when the document is not open, I still see the toolbar.

Is there a way to have the toolbar stored with the document and not with the
Word application? Where/how is the toolbar stored?

Any information is greatly appreciated.

Thanks all.
 
C

Charles Kenyon

Your code is apparently not displaying the toolbar but building it. This is
a bug if your template is being saved with the toolbar.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

C Holmes

What I find really strange is that to my knowledge the procedure which builds
the toolbar is not being called from anywhere (that I can tell). Yet after I
remove the toolbars, they show up again the next time the document is opened.

Is there a better way to create toolbars than how I am doing it by using
CommandBars.Add????
 
J

Jonathan West

C Holmes said:
What I find really strange is that to my knowledge the procedure which
builds
the toolbar is not being called from anywhere (that I can tell). Yet after
I
remove the toolbars, they show up again the next time the document is
opened.

Is there a better way to create toolbars than how I am doing it by using
CommandBars.Add????

I think we need to see the code you are using. Without that, we can't see
*where* the commandbar is placed (i.e. in what template). That is defined by
setting the CustomizationContext property just before you use the
Commandbars.Add method.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
C

C Holmes

Thanks Jonathan. Here's the procedure I wrote. What's funny is when I run it
now, it just displays a blank toolbar. It doesn't even put the controls on
the toolbar (which hasn't happened previously).

Public Sub Build_cpc2_ToolBar()

CommandBars.Add(Name:="cpc2").Visible = True
CommandBars("cpc2").Position = msoBarTop

'Build the "Level 1" combobox
Set cbolevel1 = CommandBars("cpc2").Controls.Add(Type:=msoControlComboBox)
With cbolevel1
.Style = msoComboLabel
.AddItem "1."
.AddItem "2."
.AddItem "3."
.AddItem "4."
.AddItem "5."
.Text = .List(1)
.Width = 55
.OnAction = "InsertLevel1_Manual"
.Visible = True
End With
'Build the "Level 2" combobox
Set cboLevel2 = CommandBars("cpc2").Controls.Add(Type:=msoControlComboBox)
With cboLevel2
.Style = msoComboLabel
.AddItem "(a)"
.AddItem "(b)"
.AddItem "(c)"
.AddItem "(d)"
.Text = .List(1)
.Width = 55
.OnAction = "InsertLevel2_Manual"
End With
'Build the "Level 3" combobox
Set cboLevel3 = CommandBars("cpc2").Controls.Add(Type:=msoControlComboBox)
With cboLevel3
.Style = msoComboLabel
.AddItem "(i)"
.AddItem "(ii)"
.AddItem "(iii)"
.AddItem "(iv)"
.AddItem "(v)"
.Text = .List(1)
.Width = 55
.OnAction = "InsertLevel3_Manual"
End With

'Build the "Insert Image" button
Set cmdImage = CommandBars("cpc2").Controls.Add(Type:=msoControlButton)
With cmdImage
.Caption = "Insert Image"
.Style = msoButtonCaption
.OnAction = "InsertImage"
.TooltipText = "Link to an image"
End With

End Sub
 
C

Charles Kenyon

CommandBars.Add builds a toolbar.

Once you have a toolbar in a template you can turn the visible property (or
the enabled property) for that toolbar to true or false.
The original toolbar can be built manually using the Customize toolbox or
using code.

Application.CommandBars("My Toolbar").visible = True

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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