Search code examples
vbaoutlookribbonx

Adding a button to outlook main application window's Ribbon UI via VBA?


Simple google search resulted in this answer

It states:

You have to add a CustomUI.XML to the file with XML code that links to VBA code for the buttons

Next, iteration revealed how it is usually done for MS Word VBA programming:

(Code taken from here)

Sub ShowCustomXmlParts() 
    On Error GoTo Err 
 
    Dim cxp1 As CustomXMLPart 
 
    Dim cxn As CustomXMLNode 
    Dim cxns As CustomXMLNodes 
    Dim strXml As String 
    Dim strUri As String 
 
        ' Example written for Word. 
 
        ' Add a custom XML part. 
        ActiveDocument.CustomXMLParts.Add "<custXMLPart />" 
 
        ' Returns the first custom XML part with the given root namespace. 
        Set cxp1 = ActiveDocument.CustomXMLParts("urn:invoice:namespace")         
 
        ' Get a node using XPath.                              
        Set cxn = cxp1.SelectSingleNode("//*[@quantity < 4]")  
     
    Exit Sub 
                 
' Exception handling. Show the message and resume. 
Err: 
        MsgBox (Err.Description) 
        Resume Next 
End Sub

However I can't find the corresponding outlook equivalent of the above code. The CustomXMLParts object reference is nowhere to be found! Am I missing a DLL?! 🤔


Solution

  • Outlook doesn't support customizing the UI from VBA. The best what you could do is to assign your VBA sub to the QAT button in Outlook. Otherwise, you need to develop an Outlook add-in if you need to place custom commands there.

    For COM (VSTO) add-ins see Walkthrough: Create a custom tab by using the Ribbon Designer.

    For web add-ins you may consider adding ribbon commands, they are still limited in comparison to what COM add-ins provide for the Fluent UI, see Add-in commands for more information.