Microsoft Office Tutorials and References
In Depth Information
Creating a Custom Toolbar
Figure 24 – Creating a Custom Toolbar
View the Appendix to learn how to store this procedure
in a Standard module.
Exl
Option Explicit¶
' * * * * *¶
'Name of the toolbar¶
Private Const BarName As String = "My own toolbar"¶
'Unique identifier for the TextBox¶
Private Const BarTextBox As String = "MyBarTB"¶
'Unique identifier for the ComboBox¶
Private Const BarComboBox As String = "MyBarCB"¶
' * * * * *¶
Sub CreateToolbar()¶
'Variable declaration¶
'The toolbar¶
Dim Bar As CommandBar¶
'A button—the usual control¶
Dim Button As CommandBarButton¶
'A submenu on the toolbar¶
Dim Submenu As CommandBarPopup¶
'A textbox on the toolbar¶
Dim TextBox As CommandBarControl¶
'A combobox on the toolbar¶
Dim ComboBox As CommandBarComboBox¶
'First delete the bar if it already exists¶
DeleteToolbar¶
'Now, create the toolbar¶
'(The position has the following options:¶
' msoBarLeft, msoBarTop, msoBarRight, msoBarBottom, msoBarFloating,¶
' msoBarPopup, msoBarMenuBar)¶
Set Bar = Application.CommandBars.Add(Name:=BarName, _¶
Position:=msoBarFloating)¶
With Bar¶
'Add one button¶
Set Button = .Controls.Add(Type:=msoControlButton)¶
'Change some properties¶
With Button¶
.FaceId = 33 'The icon¶
.Caption = "Sample 1"¶
Search JabSto ::




Custom Search