Name
commandbarcontrols.Add([Type], [Id], [Parameter], [Before], [Temporary])
Synopsis
Adds a control to a command bar and returns a reference to the new object.
|
Argument |
Settings |
|---|---|
|
|
An |
|
|
The |
|
|
A value to pass to the command via the |
|
|
The position of the control on the command bar. Default is to insert after the last control on the command bar. |
|
|
True prevents the control from being saved when Excel closes. False saves the control in the user’s .xlb file when Excel closes. Default is False. |
The following code adds a custom smiley button to the worksheet menu bar; fortunately it’s only temporary:
Sub AddCommandBarControl( )
Dim cb As CommandBar, cbc As CommandBarControl
' Get a command bar
Set cb = CommandBars("Worksheet Menu Bar")
Set cbc = cb.Controls.Add(msoControlButton, , , , True)
cbc.Caption = "Smiley"
cbc.FaceId = 1131
cbc.OnAction = "DontWorry"
End Sub
Sub DontWorry( )
MsgBox "Don't worry, be happy."
End SubBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access