Custom toolbars are a PITA. I've been struggling with them for ages -
experiencing the same problems you've reported with 'orphan' toolbars hanging
about when I thought I'd deleted them. However, I think I've finally found a
method that works.
I create the toolbar (which is called "Rerun") when a document based on a
particular template is opened using an AutoOpen macro as follows:
Sub AutoOpen()
Set myDoc = ActiveDocument
If myDoc.Type = wdTypeDocument Then SetToolbar
End Sub
Public Sub SetToolbar()
Dim bBarFound As Boolean
Dim myCommandBar As CommandBar
CustomizationContext = myDoc.AttachedTemplate
bBarFound = fcnFindToolbar("Rerun")
If bBarFound = False Then
CommandBars.Add "Rerun"
With CommandBars("Rerun")
.Position = msoBarTop
.Controls.Add msoControlButton, 1
DefineControl1
.Visible = True
End With
Else
With CommandBars("Rerun")
.Position = msoBarTop
If .Controls.Count >= 1 Then
DefineControl1
Else
.Controls.Add msoControlButton, 1
DefineControl1
End If
.Visible = True
End With
myDoc.AttachedTemplate.Saved = True
End If
End Sub
And define the button on it using:
Private Sub DefineControl1()
With CommandBars("Rerun").Controls(1)
If .Type = msoControlButton Then
.FaceId = 1020
.Caption = "Rerun Template"
.Style = msoButtonIconAndCaption
.OnAction = "RerunTemplate"
End If
End With
End Sub
Then to get rid of it again, I use an AutoClose macro that looks like this:
Sub AutoClose()
RemoveToolbar
End Sub
Public Sub RemoveToolbar()
Dim bSaved As Boolean
Dim bBarFound As Boolean
bBarFound = True
bSaved = ActiveDocument.Saved
Do
bBarFound = fcnFindToolbar("Rerun")
If bBarFound = True Then CommandBars("Rerun").Delete
Loop Until bBarFound = False
If ActiveDocument.Type = wdTypeDocument Then
If bSaved = True Then ActiveDocument.Save
On Error Resume Next
ActiveDocument.AttachedTemplate.Saved = True
End If
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
This seems to work and will even clean up any orphans that might be left
over from any previous 'messy' processes.
--
Cheers!
Gordon Bentley-Mix
Word MVP
Please post all follow-ups to the newsgroup.
Read the original version of this post in the Office Discussion Groups - no
membership required!
Dorak said:
I know how to open the normal.dot. Opened it, did not double click. Still
have no idea as to why customization would not stick when deleting the
toolbar. Nothing on the web either, that's why I asked here......Have a nice
holiday, and it's obviously not worth much more of anyone's time on this
subject. I did get it deleted using organizer.
Jay Freedman said:
If you double-clicked the file there, you opened a blank document based on
Normal.dot, and not Normal.dot itself. The default action for templates is
"New", not "Open".
To open Normal.dot itself, right-click the file and explicitly choose the
Open action.
The alternative (somewhat roundabout) is to use the Open command in Word's
File menu, change the "Files of type" dropdown to Word Template, (if
necessary navigate to the Templates folder), and select Normal.dot there.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
C:\Documents and Settings\[my user id]\Application
Data\Microsoft\Templates\Normal.dot
:
How did you open the template?
I actually opened normal.dot physically, and used customization to
delete the toolbar. Saved the template, closed, reopened, and
toolbar was back. The only way I could achieve the deletion was
through the Organizer. Just curious, anyway as to why.
:
Custom toolbars are stored in templates or documents. Unless you
save the template or document after deleting the toolbar, it
remains in the template or document.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
CJ wrote:
Can anyone advise me why a custom toolbar can't be deleted unless
it's deleted by the Organizer? Using customization/delete
deletes the toolbar, but when restarting Word, those deleted
toolbars resurface........... I found that using the Organizer
does the trick, but why would this happen?-