More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

share code 24-Jun-2019 08:23

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

Code level: intermediate    Code area: Outlook Expert Techniques Printer Friendly Version
Title: Enumerate all CommandBars
Description: This procedure creates a post in the Drafts folder containing a list of all the built-in command bars for the current Outlook window, along with the controls and IDs. It is recursive, so it handles submenus nested to any level. Run it against an open example of each type of item and each type of folder to get a complete picture of Outlook's CommandBars.
Date: 31-Jan-2007  11:54
Code level: intermediate
Code area: Outlook Expert Techniques
Posted by: Sue Mosher
This message is displayed as VB.NET
 Sub EnumCommandBars()
    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objDrafts As Outlook.MAPIFolder
    Dim objPost As Outlook.PostItem
    Dim colCB As Office.CommandBars
    Dim objCB As Office.CommandBar
    Dim strWindow As String
    Dim strExplBars As String
    Dim strInspBars As String
    Dim strText As String
    Dim arrBars() As String
    Dim i As Integer
    On Error Resume Next
    Set objOL = Application
    Set objNS = objOL.Session
    Set objDrafts = objNS.GetDefaultFolder(olFolderDrafts)
    strExplBars = "Menu Bar,Standard,Advanced,Web"
    strInspBars = "Menu Bar,Standard,Form Design,Formatting"
    strWindow = TypeName(objOL.ActiveWindow)
    Select Case strWindow
        Case "Explorer"
            Set colCB = objOL.ActiveExplorer.CommandBars
            arrBars = Split(strExplBars, ",")
        Case "Inspector"
            Set colCB = objOL.ActiveInspector.CommandBars
            arrBars = Split(strInspBars, ",")
    End Select
    If Not colCB Is Nothing Then
        Set objPost = objDrafts.Items.Add("IPM.Post")
        objPost.Subject = "CommandBars for " & strWindow & _
                          ": " & colCB.Parent.Caption
        objPost.BodyFormat = olFormatPlain
        For i = 0 To UBound(arrBars)
            Set objCB = colCB.item(arrBars(i))
            Call EnumOneBar(objCB, strText)
            strText = strText & vbCrLf & "===========" & vbCrLf
        Next
        objPost.Body = Mid(strText, 5)
        objPost.Save
        objPost.Display
    End If
    Set objOL = Nothing
    Set objNS = Nothing
    Set objDrafts = Nothing
    Set objPost = Nothing
    Set colCB = Nothing
    Set objCB = Nothing
End Sub

Sub EnumOneBar(cb As Office.CommandBar, ByRef postText)
    Dim objControl As Office.CommandBarControl
    Dim objPopupControl As Office.CommandBarPopup
    postText = postText & vbCrLf & vbCrLf & "CommandBar: " & cb.Name
    For Each objControl In cb.Controls
        If objControl.BuiltIn = True Then
            Select Case objControl.Type
                Case msoControlPopup, _
                     msoControlButtonPopup, _
                     msoControlGraphicPopup, _
                     msoControlSplitButtonPopup
                    postText = postText & vbCrLf & vbCrLf & _
                      objControl.Caption & _
                      " (Submenu) - " & objControl.ID
                    Set objPopupControl = objControl
                    Call EnumOneBar( _
                      objPopupControl.CommandBar, postText)
                 Case Else
                    postText = postText & vbCrLf & vbTab & _
                      objControl.Caption & " - " & objControl.ID
            End Select
        End If
    Next
    Set objControl = Nothing
    Set objPopupControl = Nothing
End Sub
All 1comments
Page [ 1  
  20-Dec-2011  16:59   
I am attempting to run this in order to find the commandbar id for 'Filter' in OL2010 and then "where I am the only one on the to list" in order to create a button that does this. Guidance on how to find/apply that command? I really want to have 4 buttons for this filter process 1) where I am the only one on the 'to' line 2)where I am on the 'to' line with other people 3) where I am on the cc list with other people and 4)reset all because I hate having to go through the advanced dialog box all the time to do this. I can create the buttons just fine, etc....but getting to that pesky filter command is proving elusive.
Page [ 1