More programming on the Microsoft Office command bar
Frank C. Rice
Microsoft Corporation
Paul Cornell
Microsoft Corporation
May 2, 2002
In the last month's column, I introduced you to the "command bar", which is in Microsoft®The user interface components used in Office, allowing you to perform operations in Office applications. Based on your feedback on the last month's column, I will introduce you to additional information and code for solving specific issues in the command bar, including:
Microsoft Outlook®How to program the command bar.
How to add custom images to the command bar button.
How to add a combo box to the command bar.
How to disable and hide the command bar and command bar controls.
How to locate the command bar.
How to dynamically add and delete the command bar.
How to list common properties of the command bar and command bar controls in a given Office application.
Command bar and Outlook Object Model
In the last month's column, I forgot to tell you how Microsoft Outlook object models access the command bar and command bar controls in a slightly different way than other Microsoft Office applications.
In applications other than Outlook, you can use the following code to access the command bar:
Public Sub ListCommandBarNames ()
'Purpose: list all command bar names of the current application.
'Note: This code is invalid for Outlook!
Dim objCommandBar As Office. CommandBar
For Each objCommandBar In Application. CommandBars
Debug. Print objCommandBar. Name
Next objCommandBar
End Sub
However, an attempt to run this code in Outlook will cause a running error. Instead, you must use the CommandBars attribute of the Explorer or Inspector object, as shown below: