How do I add a Button to a toolbar that will run a macro/procedure

B

Boogie La La

Either I'm going mad - or I'm stupid!!

I go to customize, but in the category list 'Macros' is not there!!
 
M

Mary Sauer

When you customize, click the Tools category on the left, scroll down to Macros on
the right and drag it to the toolbar.
 
E

Ed Bennett

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

Ed Bennett

Mary Sauer said:
When you customize, click the Tools category on the left, scroll down
to Macros on the right and drag it to the toolbar.

OP was looking for the Macros category on the left, which would give access
to all the available macros in the right-hand pane, as is available in other
Office applications.
 

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