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
-- 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