Search code examples
c#excelms-officeribbonribbon-control

Opening two ribbons with one load for excel 2010 with c#


I have two ribbons that I wish to load, one on the main ribbon and one in the backstage. I have to load the two within a override method but I am having troubles:

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
     return Globals.Factory.GetRibbonFactory().CreateRibbonManager(new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] 
     {
          new Ribbon1(), 
          new Backstage() as Microsoft.Office.Tools.Ribbon.IRibbonExtension 
     });
}

If I do this Ribbon1 will show but the Backstage will not, if I do it this way:

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    return new Microsoft.Office.Tools.Ribbon.RibbonManager(new Microsoft.Office.Tools.Ribbon.OfficeRibbon[]
    {
       new Ribbon1() as Microsoft.Office.Tools.Ribbon.OfficeRibbon,
       new Backstage() as Microsoft.Office.Tools.Ribbon.OfficeRibbon
    });
}

I cannot create an instance of the abstract class or interface with the RibbonManager. I am stuck, can someone help out?


Solution

  • Well I guess that you cannot actually do this, BUT I did develop a work around for those of you who are interested, which it doesn't seem like many. You can indeed combine the two XMLs and get a tandem Visual Designer Ribbon working along with a Backstage ribbon, the only problem is that you cannot create more items using the Visual Designer, you have to create them using the XML, which isn't a bad way to go, but if your end user still wants to add buttons and other items to the ribbon this can be a problem. So what I did for that was add two different projects to one solution, then you just have to have the two projects talking to each other and you have your answer. Make sure you have a reference for your main ribbon with the backstage, then you have to create a COM object in the Backstage ribbon:

    [ComVisible(true)]
    [ComDefaultInterface(typeof(IBackStageInfo))]
    

    And that is it really. Not that bad.