DocumentBase.CreateRibbonExtensibilityObject Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns an object that implements the Microsoft.Office.Core.IRibbonExtensibility interface.
protected:
virtual Microsoft::Office::Core::IRibbonExtensibility ^ CreateRibbonExtensibilityObject();
protected virtual Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject ();
abstract member CreateRibbonExtensibilityObject : unit -> Microsoft.Office.Core.IRibbonExtensibility
override this.CreateRibbonExtensibilityObject : unit -> Microsoft.Office.Core.IRibbonExtensibility
Protected Overridable Function CreateRibbonExtensibilityObject () As IRibbonExtensibility
Returns
An object that implements the Microsoft.Office.Core.IRibbonExtensibility interface.
Examples
The following code example overrides the CreateRibbonExtensibilityObject
method in the ThisAddin
or ThisDocument
class of the project and returns the Ribbon that you want to display. The example requires that you add two Ribbons to your project called Ribbon1
and Ribbon2
by using the Ribbon (Visual Designer) item. The example checks the value of a field named myCondition
and returns the appropriate Ribbon. To use this example, run it from the ThisDocument
class in a document-level project.
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
Remarks
Override this method to return an implementation of the Microsoft.Office.Core.IRibbonExtensibility
interface. If you have multiple Ribbons in your project, you can specify which Ribbons to display at run time.
You do not have to override this method to return Ribbons that you add to the project by using the Ribbon (Visual Designer) item template. By default, this method returns a RibbonManager object that represents all Ribbon (Visual Designer) items in the project. For more information, see Ribbon Overview.
You must override the CreateRibbonExtensibilityObject or RequestService method to return Ribbons in your project that you add by using the Ribbon (XML) item template. For more information about how to override the CreateRibbonExtensibilityObject method, see Ribbon XML.