Compartir a través de


Customize a ribbon for Outlook

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

When you customize the ribbon in Microsoft Office Outlook, you must consider where your custom ribbon will appear in the application. Outlook displays the ribbon in the main application user interface (UI) and in windows that open when users perform certain tasks, such as creating e-mail messages. These application windows are named inspectors.

Applies to: The information in this topic applies to VSTO Add-in projects for Outlook. For more information, see Features available by Office application and project type.

Add a custom ribbon to the main application UI

The main application UI in Outlook is called the Explorer. If you are using the Ribbon (Visual Designer) item, you can add a ribbon to the Explorer by clicking the RibbonType property of the ribbon in the Properties window, and then selecting Microsoft.Outlook.Explorer.

Assign a ribbon to an inspector

You identify the inspector you want to customize by specifying the ribbon type that corresponds to the message class for the Inspector.

If you are using the Ribbon (Visual Designer) item, click the RibbonType property of the ribbon in the Properties window, and then select one or more ribbon IDs from the list of values.

You can add more than one ribbon to a project. If more than one ribbon shares a ribbon ID, override the CreateRibbonExtensibilityObject method in the ThisAddin class of your project to specify which ribbon to display at run time. For more information, see Ribbon overview. For more information about each ribbon type, see the technical article Customize the Ribbon in Outlook 2007.

Specify the ribbon type by using ribbon XML

If you are using the Ribbon (XML) item, check the value of the ribbonID parameter in the GetCustomUI method and return the appropriate ribbon.

The GetCustomUI method is automatically generated by Visual Studio in the ribbon code file. The ribbonID parameter is a string that identifies the Explorer or a specific type of inspector. For a complete list of the possible values of the ribbonID parameter, see the technical article Customize the Ribbon in Outlook 2007.

The following code example demonstrates how to display a custom ribbon only in the Microsoft.Outlook.Mail.Compose inspector. This is the inspector that opens when a user creates a new e-mail message. The ribbon to display is specified in the GetResourceText() method, which is generated in the Ribbon class. For more information about the Ribbon class, see Ribbon XML.

public string GetCustomUI(string ribbonID)
{
    string ribbonXML = String.Empty;

    if (ribbonID == "Microsoft.Outlook.Mail.Compose")
    {
        ribbonXML = GetResourceText("Trin_RibbonOutlookBasic.Ribbon1.xml");
    }

    return ribbonXML;
}
Public Function GetCustomUI(ByVal ribbonID As String) As String _
    Implements Office.IRibbonExtensibility.GetCustomUI

    Dim ribbonXML As String = String.Empty

    If ribbonID = "Microsoft.Outlook.Mail.Compose" Then
        ribbonXML = GetResourceText("Trin_RibbonOutlookBasic.Ribbon1.xml")
    End If

    Return ribbonXML
End Function

See also