The ribbon is a way to organize related commands so that they are easier to find. Commands appear as controls on the ribbon. Controls are organized into groups along a horizontal strip at the top edge of an application window. Related groups are organized on tabs.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for the following applications: Excel; InfoPath 2013 and InfoPath 2010; Outlook; PowerPoint; Project; Visio; Word. For more information, see Features available by Office application and project type.
Customize the Microsoft Office Ribbon
To customize the ribbon, add one of the following Ribbon items to your Office project:
Ribbon (Visual Designer)
Ribbon (XML)
For example, to customize the Excel Ribbon, add a Ribbon item to an Excel VSTO Add-in project.
Ribbon (Visual Designer) item
The Ribbon (Visual Designer) item provides advanced tools that make it easier for you to design and develop a custom ribbon. Use the Ribbon (Visual Designer) item to customize the ribbon in the following ways:
Add custom or built-in tabs to a ribbon.
Add custom groups to a custom or built-in tab.
Note
A built-in tab or group is one that already exists on the ribbon of a Microsoft Office application. For example, the Data tab is a built-in tab in Excel. The Connections group is a built-in group on the Data tab.
Add custom controls to a custom group.
Add custom controls to the Backstage View.
For more information about how to customize a ribbon by using the Ribbon (Visual Designer) item, see Ribbon designer.
Ribbon (XML) item
Use the Ribbon (XML) item if you want to customize the ribbon in a way that is not supported by the Ribbon (Visual Designer) item. Use the Ribbon (XML) item to customize the ribbon in the following ways:
Add built-in groups to a custom tab or built-in tab.
Add built-in controls to a custom group.
Add custom code to override the event handlers of built-in controls.
Customize the Quick Access Toolbar.
Share a Ribbon customization between VSTO Add-in by using a qualified ID.
For more information about how to customize the ribbon by using the Ribbon (XML) item, see Ribbon XML.
Export a ribbon from the Ribbon Designer to Ribbon XML
If you create a ribbon by using the Ribbon Designer, and then decide that you want to customize the ribbon in ways that the Ribbon (Visual Designer) item does not support, you can export the ribbon to XML.
Visual Studio automatically creates a Ribbon (XML) item and populates the Ribbon XML file with elements and attributes for each control on the ribbon.
Not all of the properties that are in the Properties window of the Ribbon Designer are transferred to the Ribbon XML file. For example, Visual Studio does not export the value of the Image or Text property. That is because you must create a callback method in the Ribbon code file of the exported project to assign an image or set the text of a control. Visual Studio does not automatically generate callback methods as part of the export process.
In addition, any unchanged default property values do not appear in the resulting Ribbon XML file.
A new Ribbon code file is added to Solution Explorer. This file contains the Ribbon XML class. You must create callback methods in the Ribbon Callbacks region of this class to handle user actions, such as clicking a button. Move your code from the event handlers to these callback methods and modify the code to work with the Ribbon extensibility (RibbonX) programming model. For more information, see Ribbon XML.
You must also add code to the ThisAddIn, ThisWorkbook, or ThisDocument class that overrides the CreateRibbonExtensibilityObject method and returns the Ribbon XML class to the Office application.
An Inspector is a window that opens when users perform certain tasks, such as creating an e-mail message.
Select which ribbon to display at run time.
Select which ribbons to display at run time
Because a project can contain more than one ribbon, you can select which ribbon to display at run time.
To select a ribbon to display at run time, override the CreateRibbonExtensibilityObject method in the ThisAddin, ThisWorkbook, or ThisDocument class of your project and return the ribbon that you want to display. The following example checks the value of a field named myCondition and returns the appropriate ribbon.
Note
The syntax used in this example returns a ribbon that was created by using the Ribbon (Visual Designer) item. The syntax for returning a ribbon that is created by using a Ribbon (XML) item is slightly different. For more information about returning a Ribbon (XML) item, see Ribbon XML.
protected override Microsoft.Office.Core.IRibbonExtensibility
CreateRibbonExtensibilityObject()
{
if (myCondition == true)
{
return Globals.Factory.GetRibbonFactory().CreateRibbonManager(
new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new Ribbon1() });
}
else
{
return Globals.Factory.GetRibbonFactory().CreateRibbonManager(
new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new Ribbon2() });
}
}
Protected Overrides Function CreateRibbonExtensibilityObject() As _
Microsoft.Office.Core.IRibbonExtensibility
If myCondition = True Then
Return Globals.Factory.GetRibbonFactory().CreateRibbonManager _
(New Microsoft.Office.Tools.Ribbon.IRibbonExtension() _
{New Ribbon1()})
Else
Return Globals.Factory.GetRibbonFactory().CreateRibbonManager _
(New Microsoft.Office.Tools.Ribbon.IRibbonExtension() _
{New Ribbon2()})
End If
End Function
Shows you how to create a custom Ribbon tab by using the Ribbon Designer. You can use the Ribbon Designer to add and position controls on the custom tab.
Shows how to show, hide, and modify the ribbon, and enable users to run the code from controls in a custom task pane, actions pane, or Outlook form region.