Word 2007: Custom CommandBars Conundrum

G

gravyface

Have a specific template I use for macro customizations called "macros.dot"
-- this is copied into each users' startup folder.
I'd like to add a CommandBarButton called "Copy to AddressBook" as the first
item, above Copy/Paste, in every CommandBar.

It works, but for some reason, it keeps saving the changes to the normal.dot
template, so when a new document is opened/created, there's two items in the
menu. For example, when you open up a previously-saved .doc document, both
menu items are there, and it prompts to save changes to "Blocks, Headers..."
etc. Even if you say no, it still modifies the Normal.dot template.

I figured my conditional check to see if the button already exists would
take care of this (same with the context setting), but it's not:

Public Sub AutoExec()

On Error GoTo Errorhandler

Dim myControl As CommandBarButton
Dim addrButton As CommandBarButton

Dim cmdBar As CommandBar

For Each cmdBar In Application.CommandBars
CustomizationContext = ActiveDocument.AttachedTemplate
Set addrButton = cmbBar.FindControl(Tag:="AddAddressBookButton")
If addrButton Is Nothing Then
Set myControl = cmdBar.Controls _
.Add(Type:=msoControlButton, Before:=1, Temporary:=True)
With myControl
.Caption = "Copy To AddressBook"
.Tag = cmbBar.FindControl(Tag:="AddAddressBookButton")
End With
End If
Next
Exit Sub

Errorhandler:
Debug.Print cmdBar.Name
Resume Next
End Sub
 

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