custom context menu command doesnt appear for outlook contacts

I’m struggling with a problem and I really hope you can help.

I last developed software around 20 years ago and worked mainly in structured BASIC, with some minor work with VBScript in the past few years, so I’m afraid I’m a bit out of my league with modern languages/tools but I’m trying hard to catch-up.

I want to develop a simple free add-in for Microsoft Outlook 2016 (running locally, not web hosted) that allows to right click on a contact item, select a phone number for the contact, and have Outlook do a URI/URL call to the CALLTO: and/or TEL: provider/app with the relevant phone number to launch the call. Out of the box this functionality only works for Lync, Skype for Business and Teams. The add-in I’m trying to develop will extend this to any VOIP/Softphone client that supports TEL: or CALLTO: URI/URL.

My first step is just to get the context menu to appear, and I’m afraid that I’m failing at that.

I’ve developed the following code in Visual Studio using VB with the help of Github Copilot, it compiles and I can load the add-in into Outlook but it never appears when I right-click on a contact.


Imports Microsoft.Office.Tools.Outlook
Imports Outlook = Microsoft.Office.Interop.Outlook

Public Class ThisAddIn
    Private Sub ThisAddIn_Startup() Handles Me.Startup
        AddHandler Application.ItemContextMenuDisplay, AddressOf Application_ItemContextMenuDisplay
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
        RemoveHandler Application.ItemContextMenuDisplay, AddressOf Application_ItemContextMenuDisplay
    End Sub

    Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Object)
        MsgBox("Application_ItemContextMenuDisplay")
        If TypeOf Selection Is Outlook.ContactItem Then
            Dim callItem As Office.CommandBarControl = CommandBar.Controls.Add(Office.MsoControlType.msoControlButton)
            callItem.Caption = "URI Call"
            callItem.Tag = "URI Call"
            AddHandler CType(callItem, Office.CommandBarButton).Click, AddressOf callItem_Click
        End If
    End Sub

    Private Sub callItem_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
        Dim contact As Outlook.ContactItem = CType(Application.ActiveExplorer.Selection.Item(1), Outlook.ContactItem)
        Dim phoneNumbers As String = ""
        For Each phoneNumber As Object In contact.PhoneNumbers
            If TypeOf phoneNumber Is Outlook.PropertyAccessor Then
                Dim pa As Outlook.PropertyAccessor = phoneNumber.PropertyAccessor
                phoneNumbers = phoneNumbers & pa.GetProperty("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/TelephoneNumber") & Environment.NewLine
            End If
        Next
        MsgBox(phoneNumbers)
    End Sub
End Class


This add-in is shown as loaded in Outlook.

As the code stands now, I should at least get a msgbox when I right-click on a contact. (I added the line MsgBox(“Application_ItemContextMenuDisplay”) just to debug and see if I can get it to appear, and it doesnt.

Ideally if everything works (and I remove that debug msgbox) then when I right-click I should see a list of the contact’s phone numbers. Once I get that working I’ll try to get the URI call to Callto: working.

Any idea why this doesnt work? I apologize in advance if I’m missing something obvious, I’m just too new to this 😬 and I’m hoping that Github co-pilot doesnt have me barking up the wrong tree with this approach…

Leave a Comment