CommandBar Controls


CommandBarControl Object

Every control that can be added to a commandbar is a CommandBarControl object.
There are three CommandBarControl objects which you can use in your code:

  • CommandBarButton - This corresponds to the msoControlButton

In Office 2000 a CommandBarComboBox Change event was added.
These are the most common and should be used for assigning to macros.

  • CommandBarPopup - This corresponds to the msoControlPopup

This represents a menu or a shortcut menu. This type of control has its own Controls collection and allows controls to be added to it.

  • CommandBarComboBox - This corresponds to the msoControlComboBox

In Office 2000 a CommandBarComboBox Change event was added.


If you are working with msoControlEdit or msoControlDropDown you should use the generic CommandBarControl object.
A dropdown control has a list property and is an array of its list values and a listindex property.


msoControlTypes

Only five of these command bar controls can be added to your custom toolbars and menus.
msoControlType.msoControlButton - Buttons with or without images
msoControlType.msoControlEdit - Textbox allows you to enter text
msoControlType.msoControlDropDown - Only allows you to select from the list.
msoControlType.msoControlComboBox - Lets you enter a value as well as being able to select from the list.
msoControlType.msoControlPopup - Used for menus and submenus.


CommandBarControl Properties

These properties and methods are shared by all the commadbarcontrols

BeginGroupTrue if a separator appears before the control.
Built-inTrue if the control is built-in
CaptionThe text that is displayed for the control, If the control shows only an image, the caption appears when you move the mouse over the control. This can include an a&mpersand to indicate the hot key.
EnabledTrue if the control can be clicked.
FaceIdA number representing a graphic image displayed next to the control's caption.
OnActionThe name of the VBA macro to be executed when the control is clicked. This is not applicable to msoControlPopup
Parameter 
ShortcutTextMenu bar commands ??
StateUsed for checkboxes ?? msoButtonDown
StylemsoButtonStyle - Determines whether the button appears with a caption and/or image.
Tag 
ToolTipTextThe text that appears when the user moves the mouse pointer over the control.
TypeAn integer that determines the type of the control. This cannot be changed once the command has been added.

Parameter

This property can be used to hold any text string that might be useful.
One use might be to use the same Macro for several commands and then examine the Parameter property to determine which button was pressed.
This method is similar to the Application.Caller used in user defined functions.

Private Sub CalledBySeveral() 
   Select Case CommandBars.ActionCommand.Parameter
      Case "Ascending":
      Case "Descending":
   End Select
End Sub

This can be very useful for toggling


Tag

This property can be used to hold any text string that might be useful and can be used in addition to the Parameter property.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext