when adding a built-in control to a command bar, you pass the ID property for the built-in control in the ID argument of the Controls collection's Add method.
CommandBars("MyToolbar").Controls.Add Type:=msoControlType.msoControlButton, _
Type - The type of control to be added to the specified command bar. Can be one of the following MsoControlType constants.
Id - An integer that specifies a built-in control. If the value of this argument is 1, or if this argument is omitted, a blank custom control of the specified type will be added to the command bar.
Parameter - For built-in controls, this argument is used by the container application to run the command. For custom controls, you can use this argument to send information to Visual Basic procedures, or you can use it to store information about the control (similar to a second Tag property value).
Before - A number that indicates the position of the new control on the command bar. The new control will be inserted before the control at this position. If this argument is omitted, the control is added at the end of the specified command bar.
Temporary - The default value is False. True to make the new control temporary. Temporary controls are automatically deleted when the container application is closed.
Adding Custom Commands
when you create a custom command bar button, you must set both the Style and Caption properties to make sure that a caption will appear on the button.
Assigning Shortcut Keys
The following adds a menu that features a shortcut key.
You must use the MacroOptions to actually create the shortcut key (?)
Set objtoolmenu = CommandBars(1).FindControl(Id:=30007)
Set objnewmenu = objToolsMenu.Controls.Add(Type:=msoControlButton)
.OnAction = "MyCustomMacro"
.ShortcutText = "Ctrl + Shift + C"
Application.MacroOptions Macro:="MyCustomMacro", _
Application.OnKey "^+c", "MyCustomMacro" ??
© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext