Export (0) Print
Expand All

More Programming with Microsoft Office Command Bars

 

Paul Cornell
Microsoft Corporation

May 2, 2002

In last month's column, I introduced you to command bars, which are user interface components used throughout Microsoft® Office to allow users to carry out actions in Office applications. Based on your feedback regarding last month's column, I will share with you some additional information and code that deals with specific issues about command bars, specifically:

  • How Microsoft Outlook® handles command bars programmatically.
  • How to add custom images to command bar buttons.
  • How to add combo boxes to command bars.
  • How to disable and hide command bars and command bar controls.
  • How to position command bars.
  • How to dynamically add and delete command bars.
  • How to list the common properties for command bars and command bar controls in a given Office application.

Command Bars and the Outlook Object Model

In last month's column, I neglected to mention that the Microsoft Outlook object model accesses command bars and command bar controls differ slightly from the other Microsoft Office applications.

In applications other than Outlook, you use code similar to the following to access command bars:

Public Sub ListCommandBarNames()

    ' Purpose: Lists all command bar names for the current application.
    ' Note: This code will not work in Outlook!

    Dim objCommandBar As Office.CommandBar
    
    For Each objCommandBar In Application.CommandBars
    
        Debug.Print objCommandBar.Name
        
    Next objCommandBar
    
End Sub

However, attempting to do this in Outlook will result in a run-time error. Instead, you must use the CommandBars property of either the Explorer or Inspector objects, as follows:

Public Sub ListOutlookExplorerCommandBarNames()

    ' Purpose: Lists all command bar names for the current explorer.
    ' Note: This code only works in Outlook!

    Dim objCommandBar As Office.CommandBar
    
    For Each objCommandBar In Application.ActiveExplorer.CommandBars
    
        Debug.Print objCommandBar.Name
        
    Next objCommandBar
    
End Sub

In the preceding code example, replace the code ActiveExplorer with ActiveInspector to print out all the of command bar names for the active inspector. For those of you who aren't familiar with the Outlook object model, an explorer represents the Outlook user interface. An inspector represents a window that contains a specific Outlook item, such as an e-mail message or a contact, and any tabbed pages within the Outlook item (for example, the Details tab of a task item).

Adding Custom Images to Command Bar Buttons

Although you can use the CommandBarButton object's FaceId property to set a command bar button's image to a built-in image supplied by Office, you can use the CommandBarButton object's Picture property to supply an image you create. You can also use the CommandBarButton object's Mask property to create a custom transparent image.

Although there are many available image editors on shareware and freeware sites on the Web, as well as tools such as Microsoft Visual C++®, Microsoft Paint is more than sufficient to create these images. To use Paint to create these images:

  1. On the Start menu, point to Programs, point to Accessories, and click Paint.
  2. On the Image menu, click Attributes.
  3. In the Width box, type 16. In the Height box, type 16. Make sure the Pixels and Colors options are selected, and then click OK.
  4. On the View menu, point to Zoom, and then click Custom.
  5. Click the 800% option, and then click OK.
  6. On the View menu, point to Zoom, and then click Show Grid.
  7. On the View menu, make sure the Tool Box and Color Box commands are checked.
  8. Create the image using the Tool Box and Color Box controls.
  9. When you've finished creating the image, on the File menu, click Save.
  10. Save the icon as a 256 Color Bitmap.

Here's an example of an image I created:

Figure 1. Custom opaque bitmap

To create a transparent image, you must create a corresponding image mask. To do this, save the image you just created, but with a different name. For each pixel you want to be transparent, color the pixel white. For each pixel you want to be opaque, color the pixel black. Then save the image again. Here's an example of the image mask I created:

Figure 2. Custom bitmap mask

Here's some sample code showing how to add the transparent picture to the command bar button:

Public Sub NewPictureOnNewCommandBar()

    ' Purpose: Adds a picture to a command bar button.

    Dim objCommandBar As Office.CommandBar
    Dim objCommandBarButton As Office.CommandBarButton
    Dim objPicture As stdole.IPictureDisp

    ' Comment the next line of code if you don't want a transparent image.
    Dim objMask As stdole.IPictureDisp

    Const PICTURE_PATH As String = "C:\My Pictures\OK.bmp"

    ' Comment the next line of code if you don't want a transparent image.
    Const PICTURE_MASK As String = "C:\My Pictures\OKMask.bmp"

    Const COMMAND_BAR_NAME As String = "Test Command Bar"

    ' Replace the next line with:
    ' For Each objCommandBar In Application.ActiveExplorer.CommandBars <- For Outlook
    ' For Each objCommandBar In Application.VBE.CommandBars <- For Visual Basic Editor
    For Each objCommandBar In Application.CommandBars
    
        If objCommandBar.Name = COMMAND_BAR_NAME Then
        
            objCommandBar.Delete
            
        End If
    
    Next objCommandBar
    
    Set objCommandBar = Application.CommandBars.Add(COMMAND_BAR_NAME)
    Set objCommandBarButton = _
        objCommandBar.Controls.Add(msoControlButton)
    Set objPicture = LoadPicture(PICTURE_PATH)

    ' Comment the next line of code if you don't want a transparent image.
    Set objMask = LoadPicture(PICTURE_MASK)

    objCommandBarButton.Picture = objPicture

    ' Comment the next line of code if you don't want a transparent image.
    objCommandBarButton.Mask = objMask

End Sub

As you can see in the preceding code, you create one object in code for the opaque image and one object in code for the image mask; each object must be of type stdole.IPictureDisp. Next, initialize each of these two objects by calling the objects' LoadPicture method. Finally, set the Picture property of the command bar button object to the opaque image object, and set the Mask property of the command bar button object to the image mask.

Here's what the finished results look like for opaque and transparent images:

Figure 3. Opaque and transparent images on a command bar button

By the way, don't confuse the CommandBarButton object's FaceId property with the CommandBarButton object's Id property. The Id property determines the built-in action for that command bar control. The default value of the Id property for all custom command bar controls is 1. Setting the Id property of a custom command bar control to a number other than 1 will set the action of the custom command bar control to a built-in action if one exists for that ID in the application. For reference, the following code lists all of the IDs for all of the command bar controls in the application:

Public Sub ListCommandBarControlIDs()

    ' Purpose: Lists all command bar control IDs for the 
    ' current application.

    Dim objCommandBar As Office.CommandBar
    Dim objCommandBarControl As Office.CommandBarControl
    
    ' Replace the next line with:
    ' For Each objCommandBar In Application.ActiveExplorer.CommandBars <- For Outlook
    ' For Each objCommandBar In Application.VBE.CommandBars <- For Visual Basic Editor
    For Each objCommandBar In Application.CommandBars
    
        For Each objCommandBarControl In objCommandBar.Controls
        
            Debug.Print objCommandBarControl.Caption & " " & _
                objCommandBarControl.ID
            
        Next objCommandBarControl
    
    Next objCommandBar
    
End Sub

Adding Combo Boxes to Command Bars

To add a combo box to a command bar, use the CommandBarControls collection's Add method, passing the msoControlComboBox enumerated constant in for the Type argument. Then use the CommandBarComboBox object's AddItem method to add choices to the combo box.

The following function adds a combo box to an existing command bar:

Public Function AddComboBoxToCommandBar(ByVal strCommandBarName As String, _
        ByVal strComboBoxCaption As String, _
        ByRef strChoices() As String) As Boolean

    ' Purpose: Adds a combo box to a command bar.
    ' Accepts:
    '   strCommandBarName: The name of the command bar to add the combo box.
    '   strChoices(): An array of combo box choices.
    ' Returns: True if the combo box was successfully added to the command bar.
    
    Dim objCommandBarControl As Office.CommandBarControl
    Dim objCommandBarComboBox As Office.CommandBarComboBox
    Dim varChoice As Variant
    
    On Error GoTo AddComboBoxToCommandBar_Err
    
    ' Delete any previously-added instances of this combo box.
    ' Replace the next line of code with:
    ' For Each objCommandBarControl In _
    '   Application.ActiveExplorer.CommandBars.Item(strCommandBarName).Controls _
  <- For Outlook
    ' For Each objCommandBarControl In _
    '   Application.VBE.CommandBars.Item(strCommandBarName).Controls _
          <- For Visual Basic Editor
    For Each objCommandBarControl In Application.CommandBars.Item(strCommandBarName).Controls

        If objCommandBarControl.Caption = strComboBoxCaption Then
    
            objCommandBarControl.Delete
    
        End If

    Next objCommandBarControl

    ' Create the combo box.
    ' Replace the next line of code with:
    ' Set objCommandBarComboBox = _
    '   Application.CommandBars.Item(strCommandBarName).Controls.Add(msoControlComboBox) _
  <- For Outlook
    ' Set objCommandBarComboBox = _
    '   Application.CommandBars.Item(strCommandBarName).Controls.Add(msoControlComboBox) _
  <- For Visual Basic Editor
    Set objCommandBarComboBox = _
      Application.CommandBars.Item(strCommandBarName).Controls.Add(msoControlComboBox)
       
    objCommandBarComboBox.Caption = strComboBoxCaption
    
    For Each varChoice In strChoices
    
        objCommandBarComboBox.AddItem varChoice
        
    Next varChoice
    
AddComboBoxToCommandBar_End:
    
    AddComboBoxToCommandBar = True
    Exit Function
        
AddComboBoxToCommandBar_Err:

    AddComboBoxToCommandBar = False
    
End Function

You can test this function with code similar to the following:

Public Sub TestAddComboBoxToCommandBar()

    ' Purpose: Tests the AddComboBoxToCommandBar function.

    Dim strChoices(4) As String
    
    strChoices(1) = "Vanilla"
    strChoices(2) = "Chocolate"
    strChoices(3) = "Strawberry"
    strChoices(4) = "Other"
    
    If AddComboBoxToCommandBar("Tools", "Favorite Ice Cream", _
        strChoices) = True Then
        
        MsgBox "Combo box successfully added."
        
    Else
    
        MsgBox "Could not add combo box."
        
    End If
    
End Sub

Disabling and Hiding Command Bars and Command Bar Controls

As you develop Office solutions, you may want to prevent users from clicking on certain command bars and command bar controls associated with the solution. For example, you may want to prevent users from clicking any of the controls on the Forms toolbar to modify a custom form you created in Microsoft Word. Or you may want to disable the Macro command on the Tools menu for a given solution.

You set the Enabled property of a command bar or command bar control to False to disable a command bar or command bar control; likewise, you set the Enabled property of a command bar or command bar control to True to enable a command bar or command bar control.

You set the Visible property of a command bar or command bar control to False to hide a command bar or command bar control; likewise, you set the Visible property of a command bar or command bar control to True to show a command bar or command bar control.

To try this out, enter each of the following lines of code into the Immediate window. Each line of code will toggle the enabled or visible state of the command bar or command bar control specified. Remember to use the Application.ActiveExplorer or Application.VBE nomenclature if you enter this code in Outlook or the Microsoft Visual Basic® Editor. Be sure to run each line twice to get back to the enabled or visible state you started with.

Application.CommandBars("Tools").Enabled = _
  Not Application.CommandBars("Tools").Enabled
Application.CommandBars("Tools").Controls("Macro").Enabled = _
  Not Application.CommandBars("Tools").Controls("Macro").Enabled
Application.CommandBars("Tools").controls("Macro").Visible = _
  Not Application.CommandBars("Tools").controls("Macro").Visible

Positioning Command Bars

The Position property of a command bar specifies where a command bar appears in the application. The msoBarLeft, msoBarTop, msoBarRight, and msoBarBottom enumerated constants specify that the command bar appears on the left, top, right, or bottom edges of the application. The msoBarFloating enumerated constant specifies that the command bar is not docked to an edge of the application. The msoBarPopup enumerated constant specifies that the command bar is a pop-up menu.

The following function changes the position of a given command bar.

Public Function ChangeCommandBarPosition(ByVal strCommandBarName As String, _
        ByVal msoPosition As MsoBarPosition) As Boolean

    ' Purpose: Changes the position of a command bar.
    ' Accepts:
    '   strCommandBarName: The name of the command bar to change position.
    ' Returns: True if the command bar was successfully moved.
    
    On Error GoTo ChangeCommandBarPosition_Err
    
    ' Replace the next line of code with:
    ' Application.ActiveExplorer.CommandBars.Item(strCommandBarName).Position = _
  msoPosition <- For Outlook
    ' Application.VBE.CommandBars.Item(strCommandBarName).Position = _
      msoPosition <- For the Visual Basic Editor
    Application.CommandBars.Item(strCommandBarName).Position = msoPosition
    
ChangeCommandBarPosition_End:
    
    ChangeCommandBarPosition = True
    Exit Function
        
ChangeCommandBarPosition_Err:

    ChangeCommandBarPosition = False
    
End Function

You can test this function with code similar to the following:

Public Sub TestChangeCommandBarPosition()

    ' Purpose: Tests the ChangeCommandBarPosition function.
    
    If ChangeCommandBarPosition("Standard", msoBarFloating) = True Then
    
        MsgBox "Command bar successfully moved."
        
    Else
    
        MsgBox "Could not move command bar. Some command bars cannot " & _
            "be moved in certain ways."
    
    End If
    
End Sub

Dynamically Adding and Deleting Command Bars

There may be occasions when you want to associate command bars with specific Office documents. For example, you want to display certain custom command bars only when a specific Office document is open, and hide them when the specific Office document is closed. A good example of how to do this programmatically is by using Excel. To test this out, create a new, blank workbook and rename Sheet1 to CommandBarInfo. Type the following information into the CommandBarInfo worksheet:

Figure 4. Information to dynamically create a command bar in Excel

In the Visual Basic Editor, add the following code to a new code module associated with your new, blank workbook:

Public Function CreateCommandBarPopup() As Boolean

    ' Purpose: Creates a command bar popup control with menu
    ' items, based on information provided in an Excel worksheet.
    
    ' Returns: True if the command bar popup control was
    ' successfully added.
    
    Dim objWorksheet As Excel.Worksheet
    Dim objCommandBarControl As Office.CommandBarControl
    Dim objCommandBarPopup As Office.CommandBarPopup
    Dim objCommandBarButton As Office.CommandBarButton
    Dim intRow As Integer
    
    On Error GoTo CreateCommandBarPopup_Err
    
    ' Worksheet with the command bar information on it must
    ' be named "CommandBarInfo".
    Set objWorksheet = ThisWorkbook.Sheets("CommandBarInfo")
    
    ' Delete any existing instances of this control from
    ' previous versions.
    For Each objCommandBarControl In Application.CommandBars.Item("Standard").Controls
    
        If objCommandBarControl.Caption = objWorksheet.Cells(1, 1) Then
        
            objCommandBarControl.Delete
            
        End If
        
    Next objCommandBarControl
    
    Set objCommandBarPopup = _
      Application.CommandBars.Item("Standard").Controls.Add(msoControlPopup)
        
    objCommandBarPopup.Caption = objWorksheet.Cells(1, 1)
    
    intRow = 3
    
    ' Keep adding buttons until we run out of captions.
    Do Until objWorksheet.Cells(intRow, 1) = ""
            
        With objCommandBarPopup
        
            Set objCommandBarButton = .Controls.Add(msoControlButton)
                    
            With objCommandBarButton
                    
                    .Caption = objWorksheet.Cells(intRow, 1)
                    .OnAction = objWorksheet.Cells(intRow, 2)
                                                            
            End With
            
        End With
        
        intRow = intRow + 1
        
    Loop
    
CreateCommandBarPopup_End:

    CreateCommandBarPopup = True
    Exit Function
    
CreateCommandBarPopup_Err:
    
    CreateCommandBarPopup = False
    
End Function

Public Function DeleteCommandBarPopup() As Boolean

    ' Purpose: Deletes a command bar popup control,
    ' based on information provided in an Excel worksheet.
    
    ' Returns: True if the command bar popup control was
    ' successfully deleted.
    
    Dim objWorksheet As Excel.Worksheet
    Dim objCommandBarControl As Office.CommandBarControl
    
    On Error GoTo DeleteCommandBarPopup_Err
    
    ' Worksheet with the command bar information on it must
    ' be named "CommandBarInfo".
    Set objWorksheet = ThisWorkbook.Sheets("CommandBarInfo")
    
    ' Delete any existing instances of this control.
    For Each objCommandBarControl In Application.CommandBars.Item("Standard").Controls
    
        If objCommandBarControl.Caption = objWorksheet.Cells(1, 1) Then
        
            objCommandBarControl.Delete
            
        End If
        
    Next objCommandBarControl
    
DeleteCommandBarPopup_End:

    DeleteCommandBarPopup = True
    Exit Function
    
DeleteCommandBarPopup_Err:
    
    DeleteCommandBarPopup = False
    
End Function

Public Sub TestMacro()

    ' Purpose: Provide a test macro for completeness.
    
    MsgBox "This is a test macro."
    
End Sub

Add the following code to the ThisWorkbook module of your new, blank workbook:

Private Sub Workbook_Open()
    
    If CreateCommandBarPopup = False Then
    
        MsgBox "Could not correctly add the popup menu."
    
    Else
    
        MsgBox "Popup menu successfully added."
        
    End If

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    If DeleteCommandBarPopup = False Then
    
        MsgBox "Could not correctly delete the popup menu."
            
    Else
    
        MsgBox "Popup menu successfully deleted."
        
    End If
    
End Sub

Save and close the workbook, and then reopen the workbook. Notice that the Household Chores pop-up menu has been added to the Standard toolbar. Also notice that when you close the workbook, the Household Chores pop-up menu disappears.

For a more detailed version of this technique, see the solution presented by John Walkenbach, an Excel Most Valuable Professional (MVP), at http://j-walk.com/ss/excel/tips/tip53.htm.

The CommandBarDocumenter and CommandBarControlDocumenter Subroutines

As I develop command bar solutions, I frequently need to get a particular command bar or command bar control index, name, or caption. I created the CommandBarDocumenter and CommandBarControlDocumenter subroutines to document the common properties of all command bars and command bar controls in a given Office application.

To run these samples, copy the following code to a Microsoft Office XP application's code module in the Visual Basic Editor and then run either or both of the following subroutines. When prompted, save the results as text files (.txt). This makes the results easier to load into an application such as Microsoft Excel for viewing and filtering.

Public Sub CommandBarDocumenter()

    ' Purpose: Writes, to a text file, information about all
    ' command bars in the current application.
    
    ' You must first set a reference to the Microsoft Scripting Runtime
    ' (scrrun.dll) for this code to run correctly.
    
    ' Note: This code only works with Microsoft Office XP.
    
    Dim objCommandBar As Office.CommandBar
    Dim strType As String
    Dim strPosition As String
    Dim objFileSaveDialog As Office.FileDialog
    Dim objFSO As Scripting.FileSystemObject
    Dim objTextStream As Scripting.TextStream
    Const SAVE_BUTTON As Integer = -1
    
    Set objFileSaveDialog = Application.FileDialog(msoFileDialogSaveAs)
    
    objFileSaveDialog.Title = "Save Results As"
    
    ' User clicked "Save" button.
    If objFileSaveDialog.Show = SAVE_BUTTON Then
     
        Set objFSO = New Scripting.FileSystemObject
        Set objTextStream = objFSO.CreateTextFile(objFileSaveDialog.SelectedItems.Item(1))
        
        objTextStream.WriteLine "Name" & vbTab & _
            "Type" & vbTab & _
            "Enabled" & vbTab & _
            "Visible" & vbTab & _
            "Index" & vbTab & _
            "Position" & vbTab & _
            "Protection" & vbTab & _
            "Row Index" & vbTab & _
            "Top" & vbTab & _
            "Height" & vbTab & _
            "Left" & vbTab & _
            "Width"
        
        ' Replace the next line with:
        ' For Each objCommandBar In Application.ActiveExplorer.CommandBars _
           <- For Outlook
        ' For Each objCommandBar In Application.VBE.CommandBars <- For _
            Visual Basic Editor
        For Each objCommandBar In Application.CommandBars
    
            Select Case objCommandBar.Type
                Case msoBarTypeMenuBar
                    strType = "Menu Bar"
                Case msoBarTypeNormal
                    strType = "Normal"
                Case msoBarTypePopup
                    strType = "Pop-Up"
            End Select
        
            Select Case objCommandBar.Position
                Case msoBarBottom
                    strPosition = "Bottom"
                Case msoBarFloating
                    strPosition = "Floating"
                Case msoBarLeft
                    strPosition = "Left"
                Case msoBarMenuBar
                    strPosition = "Menu Bar"
                Case msoBarPopup
                    strPosition = "Pop-Up"
                Case msoBarRight
                    strPosition = "Right"
                Case msoBarTop
                    strPosition = "Top"
            End Select
        
            Select Case objCommandBar.Protection
                Case msoBarNoChangeDock
                    strProtection = "No Change Dock"
                Case msoBarNoChangeVisible
                    strProtection = "No Change Visible"
                Case msoBarNoCustomize
                    strProtection = "No Customize"
                Case msoBarNoHorizontalDock
                    strProtection = "No Horizontal Dock"
                Case msoBarNoMove
                    strProtection = "No Move"
                Case msoBarNoProtection
                    strProtection = "No Protection"
                Case msoBarNoResize
                    strProtection = "No Resize"
                Case msoBarNoVerticalDock
                    strProtection = "No Vertical Dock"
            End Select
            
            objTextStream.WriteLine objCommandBar.Name & vbTab & _
                strType & vbTab & _
                objCommandBar.Enabled & vbTab & _
                objCommandBar.Visible & vbTab & _
                objCommandBar.Index & vbTab & _
                strPosition & vbTab & _
                strProtection & vbTab & _
                objCommandBar.RowIndex & vbTab & _
                objCommandBar.Top & vbTab & _
                objCommandBar.Height & vbTab & _
                objCommandBar.Left & vbTab & _
                objCommandBar.Width
            
        Next objCommandBar
    
        objTextStream.Close
        
        MsgBox "Results written to " & objFileSaveDialog.SelectedItems.Item(1) & "."
    
    End If
    
End Sub

Sub CommandBarControlDocumenter()

    ' Purpose: Writes, to a text file, information about all
    ' command bar controls in the current application.

    ' You must first set a reference to the Microsoft Scripting Runtime
    ' (scrrun.dll) for this code to run correctly.
    
    ' Note: This code only works with Microsoft Office XP.

    Dim objCommandBar As Office.CommandBar
    Dim objCommandBarControl As Office.CommandBarControl
    Dim strOLEUsage As String
    Dim strType As String
    Dim objFileSaveDialog As Office.FileDialog
    Dim objFSO As Scripting.FileSystemObject
    Dim objTextStream As Scripting.TextStream
    Const SAVE_BUTTON As Integer = -1
    
    Set objFileSaveDialog = Application.FileDialog(msoFileDialogSaveAs)
    
    objFileSaveDialog.Title = "Save Results As"
    
    ' User clicked "Save" button.
    If objFileSaveDialog.Show = SAVE_BUTTON Then
     
        Set objFSO = New Scripting.FileSystemObject
        Set objTextStream = objFSO.CreateTextFile(objFileSaveDialog.SelectedItems.Item(1))
        
        objTextStream.WriteLine "ID" & vbTab & _
            "Index" & vbTab & _
            "Caption" & vbTab & _
            "Parent" & vbTab & _
            "DescriptionText" & vbTab & _
            "BuiltIn" & vbTab & _
            "Enabled" & vbTab & _
            "IsPriorityDropped" & vbTab & _
            "OLEUsage" & vbTab & _
            "Priority" & vbTab & _
            "Tag" & vbTab & _
            "TooltipText" & vbTab & _
            "Type" & vbTab & _
            "Visible" & vbTab & _
            "Height" & vbTab & _
            "Width"
    
            ' Replace the next line with:
            ' For Each objCommandBar In Application.ActiveExplorer.CommandBars <- For Outlook
            ' For Each objCommandBar In Application.VBE.CommandBars _
                <- For Visual Basic Editor
            For Each objCommandBar In Application.CommandBars
            
                For Each objCommandBarControl In objCommandBar.Controls
                
                    Select Case objCommandBarControl.OLEUsage
                        
                        Case msoControlOLEUsageBoth
                            strOLEUsage = "Both"
                        Case msoControlOLEUsageClient
                            strOLEUsage = "Client"
                        Case msoControlOLEUsageNeither
                            strOLEUsage = "Neither"
                        Case msoControlOLEUsageServer
                            strOLEUsage = "Server"
                    
                    End Select
                
                    Select Case objCommandBarControl.Type
                    
                        Case msoControlActiveX
                            strType = "ActiveX"
                        Case msoControlAutoCompleteCombo
                            strType = "Auto-Complete Combo Box"
                        Case msoControlButton
                            strType = "Button"
                        Case msoControlButtonDropdown
                            strType = "Drop-Down Button"
                        Case msoControlButtonPopup
                            strType = "Popup Button"
                        Case msoControlComboBox
                            strType = "Combo Box"
                        Case msoControlCustom
                            strType = "Custom"
                        Case msoControlDropdown
                            strType = "Drop-Down"
                        Case msoControlEdit
                            strType = "Edit"
                        Case msoControlExpandingGrid
                            strType = "Expanding Grid"
                        Case msoControlGauge
                            strType = "Gauge"
                        Case msoControlGenericDropdown
                            strType = "Generic Drop-Down"
                        Case msoControlGraphicCombo
                            strType = "Graphic Combo Box"
                        Case msoControlGraphicDropdown
                            strType = "Graphic Drop-Down"
                        Case msoControlGraphicPopup
                            strType = "Popup Graphic"
                        Case msoControlGrid
                            strType = "Grid"
                        Case msoControlLabel
                            strType = "Label"
                        Case msoControlLabelEx
                            strType = "LabelEx"
                        Case msoControlOCXDropdown
                            strType = "OCX Drop-Down"
                        Case msoControlPane
                            strType = "Pane"
                        Case msoControlPopup
                            strType = "Popup"
                        Case msoControlSpinner
                            strType = "Spinner"
                        Case msoControlSplitButtonMRUPopup
                            strType = "Split Button MRU Popup"
                        Case msoControlSplitButtonPopup
                            strType = "Button Popup"
                        Case msoControlSplitDropdown
                            strType = "Split Drop-Down"
                        Case msoControlSplitExpandingGrid
                            strType = "Split Expanding Grid"
                        Case msoControlWorkPane
                            strType = "Work Pane"
            
                        End Select
                            
                        objTextStream.WriteLine objCommandBarControl.ID & _
                          vbTab & _
                            objCommandBarControl.Index & vbTab & _
                            objCommandBarControl.Caption & vbTab & _
                            objCommandBarControl.Parent.Name & vbTab & _
                            objCommandBarControl.DescriptionText & vbTab & _
                            objCommandBarControl.BuiltIn & vbTab & _
                            objCommandBarControl.Enabled & vbTab & _
                            objCommandBarControl.IsPriorityDropped & vbTab & _
                            strOLEUsage & vbTab & _
                            objCommandBarControl.Priority & vbTab & _
                            objCommandBarControl.Tag & vbTab & _
                            objCommandBarControl.TooltipText & vbTab & _
                            strType & vbTab & _
                            objCommandBarControl.Visible & vbTab & _
                            objCommandBarControl.Height & vbTab & _
                            objCommandBarControl.Width
                                                    
                    Next objCommandBarControl
                
                Next objCommandBar
                
                objTextStream.Close
        
                MsgBox "Results written to " & _
                  objFileSaveDialog.SelectedItems.Item(1) & "."
    
            End If
            
End Sub

Paul Cornell works for the MSDN Online Office Developer Center and the Office developer documentation team. Paul also writes the Office Power User Corner column for the Office Assistance Center. He spends his free time with his wife and two daughters.

Show:
© 2014 Microsoft