Adding Buttons to the Toolbar

When you add a button to the toolbar, you need to specify the macro that should be run as the OnAction property for the button. You can also specify the Caption, a FacelD property to control the icon picture, and ToolTip text. When dealing with a toolbar that displays tiny icons, it is really important to include meaningful ToolTip text.

The .Style property controls whether you see just the caption, just the icon, or the icon and caption. In Figure 24.5, the Print button has a Type property set to msoButtonCaption. The Pictures control displays both the icon and the text by setting the Type property to msoButtonlconAndCaption. The Reports icon has a Type property of msoButtonlcon.

The following code creates a toolbar with the three types of command buttons:

Sub CreateToolbar()

Dim TBar As CommandBar

Dim NewDD As CommandBarControl

Dim NewBtn as CommandBarButton

1 delete any old copy of the toolbar DeleteToolbar

1 Define the toolbar Set TBar = CommandBars.Add With TBar

.Name = "XYZ" .Visible = True .Position = msoBarFloating End With

Set NewBtn = TBar.Controls.Add(Type:=msoControlButton) With NewBtn

.OnAction = "PrintCard"

.TooltipText = "Select pages to print"

.Style = msoButtonCaption

0 0

Post a comment