共用方式為


RibbonFactory.CreateRibbonManager Method

Creates an IRibbonExtensibility object that represents a Ribbon customization.

Namespace:  Microsoft.Office.Tools.Ribbon
Assembly:  Microsoft.Office.Tools.Common (in Microsoft.Office.Tools.Common.dll)

Syntax

'Declaration
Function CreateRibbonManager ( _
    ribbons As IRibbonExtension() _
) As IRibbonExtensibility
IRibbonExtensibility CreateRibbonManager(
    IRibbonExtension[] ribbons
)

Parameters

Return Value

Type: Microsoft.Office.Core.IRibbonExtensibility
An object that represents a Ribbon customization.

Remarks

Return the IRibbonExtensibility object in the CreateRibbonExtensibilityObject method of the ThisAddin, ThisWorkbook, or ThisDocument class of your project to return the Ribbon that you want to display in the Office application.

Examples

The following example uses a condition to determine which custom Ribbon to display. This example then uses the CreateRibbonManager method to create and then return an IRibbonExtension object that represents the custom 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 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
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() });
        }
    }

.NET Framework Security

See Also

Reference

RibbonFactory Interface

Microsoft.Office.Tools.Ribbon Namespace