Microsoft Office Tutorials and References
In Depth Information
12.7 Example: Creating a Toolbar
12.7 Example: Creating a Toolbar
Let us construct a custom toolbar with four different types of controls, as shown in Figure 12-4 .
This will illustrate the use of the built-in controls. The code in Example 12-6 does the job. We will
discuss various portions of the code after you have glanced at it.
Figure 12-4. A custom toolbar
Example 12-6. An Example Toolbar
Sub CreateToolbar()
Dim cbar As CommandBar, cbctl As CommandBarControl
' Delete if it exists
For Each cbar In Application.CommandBars
If cbar.Name = "Toolbar Example" Then cbar.Delete
' Create a floating toolbar
Set cbar = Application.CommandBars.Add(Name:="Toolbar Example", _
cbar.Visible = True
' Add a custom button control to execute a macro
Set cbctl = cbar.Controls.Add(Type:=msoControlButton)
cbctl.Visible = True
cbctl.Style = msoButtonCaption
cbctl.Caption = "CustomButton"
' Run the following macro
cbctl.OnAction = "ExampleMacro"
' Add built-in Open... control
Set cbctl = cbar.Controls.Add(Id:=23)
' Icon for button
cbctl.FaceId = 23
cbctl.Visible = True
' Add built-in spell checking button
Set cbctl = cbar.Controls.Add(Id:=2)
cbctl.FaceId = 2
cbctl.Visible = True
' Add a list box
Set cbctl = cbar.Controls.Add(Type:=msoControlDropdown)
' Add a tag so macro can find it
cbctl.Tag = "ComposerList"
cbctl.Visible = True
cbctl.Caption = "ListCaption"
Search JabSto ::

Custom Search