Page 228 - Excel Progamming Weekend Crash Course
P. 228
k540629 ch16.qxd 9/2/03 9:34 AM Page 203
Session 16 — Creating Custom Toolbars 203
Restoring Toolbar Defaults
To return a built-in Excel toolbar to its default state by removing any added
buttons and restoring any deleted buttons, follow these steps:
1. Select View ➪ Toolbars ➪ Customize to display the Customize dialog box.
2. Click the Toolbars tab.
3. In the Toolbars list, select the toolbar you want to reset.
4. Click the Reset button
You cannot reset custom toolbars because they do not have a default state
associated with them.
Figure 16-8 Attaching a custom toolbar to a workbook
Hiding and Displaying Toolbars in VBA Code
It is possible to manipulate toolbars in many ways using VBA code. In particular, you can
display and hide toolbars as needed in code. This technique enables you to add a nice level
of customization to your applications, having the needed custom toolbars displayed at the
right times.
In VBA, a toolbar is referred to as a command bar. There are three types of command
bars: toolbars, menu bars, and shortcut menus. Only the toolbar type is relevant to the pre-
sent discussion.
All command bars are maintained in the Application object’s CommandBars collection.
This includes Excel’s built-in toolbars plus any custom toolbars. This collection works similar
to the other collections you have encountered in this book. You can refer to an individual
item by its position in the collection:
CommandBars(4)