Page 229 - Excel Progamming Weekend Crash Course
P. 229
k540629 ch16.qxd 9/2/03 9:34 AM Page 204
204 Saturday Afternoon
This is not particularly useful in most situations. It is much better to refer to the item by
its name:
CommandBars(name)
To make a toolbar visible, set its Visible property to True. To hide it, set this property
to False. For example, this code makes the toolbar named Data Entry visible:
CommandBars(“Data Entry”).Visible = True
You can also control the position of a toolbar by setting its Position property. The set-
tings for this property are described in Table 16-2.
Table 16-2 Settings for the CommandBar Object’s Position Property
Constant Meaning
msoBarLeft Docked on the left
msoBarRight Docked on the right
msoBarTop Docked at the top
msoBarBottom Docked on the bottom
msoBarFloating Floating
The program in Listing 16-1 shows an example that uses these properties. This program
would be used in an Excel application that includes custom toolbars named Data Entry and
Stats. When the program runs, it makes both toolbars visible and positions them docked at
the top of the worksheet window.
Listing 16-1 A program to display and position custom toolbars
Sub DisplayCustomToolbars()
CommandBars(“Data Entry”).Visible = True
CommandBars(“Data Entry”).Position = msoBarTop
CommandBars(“Stats”).Visible = True
CommandBars(“Stats”).Position = msoBarTop
End Sub
Please see Session 24 for information about protecting custom toolbars from
modification by the user.
Cross-Ref