How to remove toolbars added during development?

C

Chris

I'm developing something to distribute, and it includes a toolbar. As
I develop it, each time I've loaded it has added another copy of the
toolbar (revised) to the list in View > Toolbars. How do I get rid of
the older versions? I didn't notice these proliferating until I had
quite a few on there. Thanks for suggestions.
 
H

Helmut Weber

Hi Chris,

I'd just delete them all and add the toolbar in question again.

Sub Testxxx1()
Dim oCmd As CommandBar
For Each oCmd In ActiveDocument.CommandBars
If oCmd.name = "Test01" Then
oCmd.Delete
End If
Next
ActiveDocument.CommandBars.Add "Test01"
ActiveDocument.CommandBars("Test01").Visible = True
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
G

Gordon Bentley-Mix

Chris,

A few little things to watch out for that may come back to bite you:

Be aware of the context in which the toolbar is created; check out the VBA
help topics on CustomizationContext for more info.

Be aware that if the toolbar has been added to the Normal template
inadvertently, you may struggle to get rid of it - especially in a network
environment. It may require you to delete or rename the Normal and let Word
rebuild it automatically.

Consider running code to remove the toolbar on a Document_Close event or in
an AutoClose macro (or both).

And one final tip- There may be a more efficient way of finding your toolbar
than going through the entire CommandBars collection looking for it. (There
are over 150 CommandBar objects in this collection.) Something like the
following may help:

Public Sub RemoveToolbar()
Dim bBarFound As Boolean
bBarFound = fcnFindToolbar("myToolbar")
If bBarFound = True Then CommandBars("myToolbar").Delete
End Sub

Public Function fcnFindToolbar(myToolbarName As String) As Boolean
Dim myValue As String
fcnFindToolbar = False
On Error Resume Next
myValue = CommandBars(myToolbarName).Name
If Err.Number = 0 Then fcnFindToolbar = True
End Function

(Thanks to Greg Maxey for the direction on using this method, which has been
adapted from code for determining the existence of a document variable.)
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

Just on the off chance that you somehow end up with several of the same
toolbars again:

Private Sub RemoveToolbar()
Dim bBarFound As Boolean
bBarFound = True
Do
bBarFound = fcnFindToolbar("Rerun")
If bBarFound = True Then CommandBars("Rerun").Delete
Loop Until bBarFound = False
End Sub

Private Function fcnFindToolbar(myToolbarName As String) As Boolean
Dim myValue As String
fcnFindToolbar = False
On Error Resume Next
myValue = CommandBars(myToolbarName).Name
If Err.Number = 0 Then fcnFindToolbar = True
End Function

--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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