Finding user-defined toobars

E

EllenM

Hello,

I have a very simple question pertaining to user-defined toolbars. So far, I
know how to turn on and off the visibility of toobars (either docked or
floating palettes) Example below:

CommandBars("GRPT_Toolbar").Visible = True

The dilemma I face is trying to write a script to first test for the
existence of a user-defined toobar before I try to reference it in other
places of the automacro I am writing.

In case you are wondering, I need this because I have an embedded automacro
in a template that references these user-defined toobars. As such, there is
the potential of someone receiving a document from which my template is
based, but not having the toobar on his/her machine. Of course, they will get
an error since the script is referencing something that is not there. I know
the bookmark object has such properties for testing for the existence of
bookmarks. Is there something similar for toobars? If not, is there some sort
of exception hander I could use to filter the error?

Thanks
 
R

Russ

Ellen,
This example was found when I entered commandbar into Word VBA Help and
selected commandbar object.


foundFlag = False
For Each cb In CommandBars
If cb.Name = "Forms" Then
cb.Protection = msoBarNoChangeDock
cb.Visible = True
foundFlag = True
End If
Next cb
If Not foundFlag Then
MsgBox "The collection does not contain a Forms command bar."
End If
'
In the first "If", I would also use 'Exit For' to stop iterating, once the
name we want is found.
 
E

EllenM

Thanks so much, Russ. It works!!

Russ said:
Ellen,
This example was found when I entered commandbar into Word VBA Help and
selected commandbar object.


foundFlag = False
For Each cb In CommandBars
If cb.Name = "Forms" Then
cb.Protection = msoBarNoChangeDock
cb.Visible = True
foundFlag = True
End If
Next cb
If Not foundFlag Then
MsgBox "The collection does not contain a Forms command bar."
End If
'
In the first "If", I would also use 'Exit For' to stop iterating, once the
name we want is found.
 

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