Boogie La La said:
Either I'm going mad - or I'm stupid!!
Here's some code I posted almost exactly two years ago to this group:
===
Public WithEvents cbbButton As Office.CommandBarButton
Sub Dummy()
MsgBox "Dummy"
End Sub
Private Sub cbbButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
Dummy
End Sub
Private Sub Document_BeforeClose(Cancel As Boolean)
cbbButton.Delete
End Sub
Private Sub Document_Open()
Dim cbBar As Office.CommandBar
On Error Resume Next
Set cbBar = Publisher.CommandBars("Macros")
If Err.Number = 0 Then
'everything is fine
Else
Set cbBar = Publisher.CommandBars.Add("Macros")
Err.Clear
End If
Set cbbButton = cbBar.Controls(msoControlButton)
If Err.Number = 0 Then
'everything is fine
Else
Set cbbButton = cbBar.Controls.Add(msoControlButton)
End If
Err.Clear
'you can insert some code to format the button here
End Sub
===
This creates a new button on a toolbar named "Macros", and calls the Dummy
subroutine.