How to: Export a ribbon from the Ribbon Designer to Ribbon XML
Applies to: Visual Studio Visual 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
The Ribbon (Visual Designer) item does not support all possible types of Ribbon customization. To customize the ribbon in advanced ways, you can export the ribbon from the designer to Ribbon XML and edit the XML directly.
Note
Not all property values appear in the Ribbon XML file. For more information, see Ribbon overview.
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.
To export a ribbon from the Ribbon Designer to Ribbon XML
Right-click the Ribbon code file in Solution Explorer, and then click View Designer.
Right-click the Ribbon Designer, and then click Export Ribbon to XML.
Visual Studio adds a Ribbon XML file and a Ribbon XML code file to your project.
In the Ribbon code class, locate the comments that start with
TODO:
.Copy the code block in these comments to the ThisAddin, ThisWorkbook, or ThisDocument class, depending on which type of solution you are developing.
This code enables the Microsoft Office application to discover and load your custom ribbon. For more information, see Ribbon XML.
In the ThisAddin, ThisWorkbook, or ThisDocument class, uncomment the code block.
After you uncomment the code, it should resemble the following example. In this example, the Ribbon class is called
MyRibbon
.protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject() { return new MyRibbon(); }
Protected Overrides Function CreateRibbonExtensibilityObject() As _ Microsoft.Office.Core.IRibbonExtensibility Return New MyRibbon() End Function
Switch to the Ribbon XML code file and find the
Ribbon Callbacks
region.This is where you write callback methods to handle user actions, such as clicking a button.
Create a callback method for each event handler that you wrote in the Ribbon Designer code.
Move all your event handler code from the event handlers to the callback methods, and modify the code to work with the Ribbon extensibility (RibbonX) programming model.
For information about writing callback methods and using the RibbonX programming model, see Ribbon XML.