none
Outlook 2007 Right Click Menu For Selected Contacts RRS feed

  • Question

  • I found from one of your forums how to add a command button of something to the Right Click Menu when I select an E-mail. I then found out the way to change it so it adds the command button to the Right Click Menu when I select a Contact.

    I have many many userforms that will run from a code in ThisOutlookSession areas as a macro to the userform, and as an example to run a userform, it is simply:

     Public Sub runthis74()
        Dim frm As New UserForm70
        frm.Show
           
    End Sub

    So for the code in creating the command button for the Right Click Menu, I also found out that the command button will run the code from the ThisOutlookSession, so when I right click after selecting a contact, it shows the userform as a commandbutton to it....and what you will see below, is how I did it to show many userforms from a new command button...

    So what I am trying to do, is change this code, so that it works when I select more than one contact...not just one contact..so here is the big code and would love to hear back...thanks much

    Private Sub Application_ItemContextMenuDisplay( _
        ByVal CommandBar As Office.CommandBar, _
        ByVal Selection As Selection)
    
        Dim objButton As CommandBarButton
        Dim objButton2 As CommandBarButton
        Dim objButton3 As CommandBarButton
        
        Dim objButton4 As CommandBarButton
        Dim objButton5 As CommandBarButton
        Dim objButton6 As CommandBarButton
        Dim objButton7 As CommandBarButton
        Dim objButton8 As CommandBarButton
        Dim objButton9 As CommandBarButton
        Dim objButton10 As CommandBarButton
        Dim objButton11 As CommandBarButton
        Dim objButton12 As CommandBarButton
        Dim objButton13 As CommandBarButton
        Dim objButton14 As CommandBarButton
        Dim objButton15 As CommandBarButton
        Dim objButton16 As CommandBarButton
        Dim objButton17 As CommandBarButton
        Dim objButton18 As CommandBarButton
        
        Dim intButtonIndex As Integer
        Dim intCounter As Integer
        
        On Error GoTo ErrRoutine
        
        ' Ensure we have only one item selected.
        If Selection.Count = 1 Then
              
            ' Ensure we have a MailItem selected.
            If Selection.Item(1).Class = olContact Then
                ' Find the location of the Reply To All button.
                For intCounter = 1 To CommandBar.Controls.Count
                    If CommandBar.Controls(intCounter).ID = 355 Then
                        intButtonIndex = intCounter
                        Exit For
                    End If
                Next
                
                ' If we have a Reply To All button in the
                ' context menu, add a new button to support
                ' the ReplyToNoncopied routine.
                If intButtonIndex <> 0 Then
                    ' Create a new menu item and place it
                    ' just after the Reply To All button
                    Set objButton = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                    
                           Set objButton2 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                          Set objButton3 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                        
                        Set objButton4 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                                                                
                        Set objButton5 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton6 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton7 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton8 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton9 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton10 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton11 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton12 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton13 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton14 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton15 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton16 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton17 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                         Set objButton18 = CommandBar.Controls.Add( _
                        msoControlButton, , , intButtonIndex)
                        
                              
                        
                    ' Configure the menu item.
                    With objButton
                        .Style = msoButtonIconAndCaption
                        .Caption = "Marketing E-Mails"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis48"
                       
                        
                    End With
                    
                       With objButton2
                        .Style = msoButtonIconAndCaption
                        .Caption = "LinkedIn Marketing E-Mails"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis72"
                       
                        
                    End With
                    
                    With objButton3
                        .Style = msoButtonIconAndCaption
                        .Caption = "All Status Fields"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis39"
                       
                        
                    End With
                    
                       With objButton4
                        .Style = msoButtonIconAndCaption
                        .Caption = "E-mails to Lawyers"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis73"
                       
                        
                    End With
                    
                         With objButton5
                        .Style = msoButtonIconAndCaption
                        .Caption = "E-mails to Bankers"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis69"
                       
                        
                    End With
                    
                         With objButton6
                        .Style = msoButtonIconAndCaption
                        .Caption = "Group E_Mail From Lou Stoler and Catch Up"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis64"
                       
                        
                    End With
                    
                    With objButton7
                        .Style = msoButtonIconAndCaption
                        .Caption = "Group Thank-You E-Mails"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis55"
                       
                        
                    End With
                    
                        With objButton8
                        .Style = msoButtonIconAndCaption
                        .Caption = "Group E-Mails Follow-Up Events"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis60"
                       
                    End With
                    
                    With objButton9
                        .Style = msoButtonIconAndCaption
                        .Caption = "Delete Fields"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis51"
                       
                    End With
                    
                          With objButton10
                        .Style = msoButtonIconAndCaption
                        .Caption = "Convert Fields"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis52"
                       
                    End With
                    
                           With objButton11
                        .Style = msoButtonIconAndCaption
                        .Caption = "Search Contacts & E-Mails"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis63"
                       
                    End With
                    
                          With objButton12
                        .Style = msoButtonIconAndCaption
                        .Caption = "Categories"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis26"
                       
                    End With
                    
                        With objButton13
                        .Style = msoButtonIconAndCaption
                        .Caption = "List of Last Status, Next Step, Dates"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis67"
                       
                    End With
                    
                           With objButton14
                        .Style = msoButtonIconAndCaption
                        .Caption = "Move Attachments to Folder"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis68"
                       
                    End With
                    
                     With objButton15
                        .Style = msoButtonIconAndCaption
                        .Caption = "Move Contacts"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis62"
                       
                    End With
                    
                     With objButton16
                        .Style = msoButtonIconAndCaption
                        .Caption = "Move Bank Contacts"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis66"
                       
                    End With
                    
                     With objButton17
                        .Style = msoButtonIconAndCaption
                        .Caption = "Move E-Mails To Folder"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis61"
                       
                    End With
                    
                    With objButton18
                        .Style = msoButtonIconAndCaption
                        .Caption = "Userforms and E-mails"
                        .Parameter = Selection.Item(1).EntryID
                        .FaceId = 355
                        ' If you place this sample in a class module
                        ' other than ThisOutlookSession, update this
                        ' line of code to ensure that the OnAction
                        ' property contains the correct project,
                        ' class, and routine name.
                        .OnAction = "Project1.ThisOutlookSession.runthis47"
                       
                    End With
                End If
            End If
        End If
        
    EndRoutine:
        On Error GoTo 0
        ' Place clean-up code here.
        Exit Sub
        
    ErrRoutine:
        MsgBox Err.Number & " - " & Err.Description, _
            vbOKOnly Or vbCritical, _
            "Application_ItemContextMenuDisplay"
        GoTo EndRoutine
    End Sub
    
    

    Wednesday, May 28, 2014 12:13 AM

All replies