'***********************************************************
'Copy and paste the following code into a standart module
'CreateCommandButton macro to create the new button
'RemoveCommandButton macro to create the new button
'***********************************************************
Option Explicit
Public Sub CreateCommandBarButton()
'Remove the button if it is already existing
Call RemoveCommandBarButton
'Create new control button
'Temporary:=True : Available from now on
'Temporary:=False : Available only this session
With Application.CommandBars("Standard").Controls. _
Add(msoControlButton, Temporary:=True)
'Caption to display on button
.Caption = "New Button"
'Procedure name to run when button is clicked
.OnAction = "MyMacro"
'Button Style - msoButtonCaption = 2
.Style = 2
'Show new button
.Visible = True
End With
End Sub
Public Sub RemoveCommandBarButton()
'Error handler if control is not existing
On Error Resume Next
'Remove custom control button
Application.CommandBars("Standard") _
.Controls("New Button").Delete False
End Sub