Command Bars

In VBA, command bars represent a number of user interface entities such as toolbars, menu bars, and shortcut menus (via right-click). You can declare variables in VBA as a CommandBar object type. To demonstrate, the next program code declares a CommandBar object variable and uses a For Each loop to iterate through each CommandBar object found in the CommandBars collection. Each command bar's name is printed to the Immediate window. Output is seen in Figure 11.6.

Private Sub cmdFindCommandBars_Click() Dim myCommandBar As CommandBar

For Each myCommandBar In CommandBars

Debug.Print myCommandBar.Name Next myCommandBar End Sub

Using the CommandBar object to iterate through each command bar in a CommandBars collection.

Using the CommandBar object to iterate through each command bar in a CommandBars collection.

The CommandBars collection contains all command bar objects in the current application.

Was this article helpful?

0 0

Post a comment