none
Ribbon not loading and CreateRibbonExtensibilityObject method not getting called RRS feed

  • Question

  • Hello,

    I have created an application level Excel Addin using VS 2010 premium, 3.5 Framework, VSTO 4.0 on an XP machine. I was able to install the same Addin on machines with Excel 2010 and as well as machines with Excel 2007 all this time. I have been deploying this addin since almost a year without any issues.

    But recently my machine got upgraded to Windows 7 with same VS 2010 Premium. Now when i build the same solution and use that MSI to install on a machine with Office 2007 and XP, the install goes fine but i dont see the Ribbon loaded. I tried doing some troubleshooting and noticed that the method CreateRibbonExtensibilityObject() never gets called on office 2007 but the same method gets called on office 2010 machine and Ribbon also shows up fine there. So basically my addin does not show up on office 2007 but works fine on office 2010.

    I generate my Ribbon dynamically. And also my ThisAddin_Startup and ThisAddin_shutdown are getting called properly on office 2007 machine.

    This code is in ThisAddin.cs

    protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                return new Ribbon();
            }

    This is in Ribbon.cs

    [ComVisible(true)]
        public class Ribbon : Office.IRibbonExtensibility
        {
          public string GetCustomUI(string ribbonID)
            {
                string resourceText = string.Empty;
                resourceText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><customUI onLoad=\"Ribbon_Load\" loadImage=\"Ribbon_LoadImage\" xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\">";
                resourceText = resourceText + "<commands>";
                resourceText = resourceText + "<command idMso=\"SheetRowsInsert\" onAction=\"myRowInsert\" />";
                resourceText = resourceText + "<command idMso=\"SheetColumnsInsert\" onAction=\"myColumnInsert\" />";
                resourceText = resourceText + "<command idMso=\"SheetRowsDelete\" onAction=\"myRowDelete\" />";
                resourceText = resourceText + "<command idMso=\"SheetColumnsDelete\" onAction=\"myColumnDelete\" />";
                resourceText = resourceText + "</commands>";
                resourceText = resourceText + "<ribbon>";
                resourceText = resourceText + "<tabs>";
                resourceText = resourceText + "<tab id=\"tabExcelAddin\" label=\"ExcelAddin\">";
                resourceText = resourceText + "<group id=\"grpSwitchToUAT\" label=\"Environment\" getVisible=\"getSwitchToUATVisible\"> ";
                resourceText = resourceText + "<dropDown id=\"ddEnvironment\" onAction=\"DropDownSelectionChanged\" label=\"Choose Environment:\" showImage=\"false\" getItemCount=\"ItemCount\" getItemLabel=\"ItemLabel\">";
                resourceText = resourceText + "</dropDown>";
                resourceText = resourceText + "</group>";
                resourceText = resourceText + "<group id=\"grpAvailableDataServices\" label=\"Available Data Services V" + Utility.Resources.ExcelAddinVersion + "\">"; //Utility.Resources.ExcelAddinVersion + "\">";
                resourceText = resourceText + "<button id=\"btnLoadDataServices\" label=\"Load Data Services\" onAction =\"ReDraw\" showImage=\"false\" getVisible=\"getButtonVisible\"/>";
                resourceText = resourceText + "<dynamicMenu id=\"dmChooseDataServices\" getLabel=\"ChooseDataServices\" getContent=\"GetContent\" />";
                resourceText = resourceText + "<toggleButton id=\"tgbShowTaskPane\" onAction=\"tgbShowTaskPane_Click\" label=\"Display Data Panel\" showImage=\"false\" />";
                resourceText = resourceText + "<button id=\"btnSignOff\" label=\"Log Out\" onAction =\"signOff_Click\" showImage=\"false\" getEnabled=\"getSignOffEnabled\" getVisible=\"getSignOffVisible\"/>";
                resourceText = resourceText + "<button id=\"btnSignOn\" label=\"Log In\" onAction =\"signIn_Click\" showImage=\"false\" getEnabled=\"getSignInEnabled\" getVisible=\"getSignInVisible\"/>";
                resourceText = resourceText + "</group>";
                resourceText = resourceText + "<group id=\"grpProxySetting\" label=\"Proxy\"> ";
                resourceText = resourceText + "<button id=\"btnProxy\" label=\"Proxy Settings\" onAction =\"ProxyDisplay\" showImage=\"true\" getImage=\"GetImage\" size=\"large\" />";
                resourceText = resourceText + "</group>";
                resourceText = resourceText + "</tab>";
                resourceText = resourceText + "</tabs>";
                resourceText = resourceText + "</ribbon>";
                resourceText = resourceText + "</customUI>";
    
                return resourceText;
            }
    public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
    }

    Can someone please help me with this.

    Thanks,

    Friday, March 22, 2013 9:31 PM

Answers

  • try to now override CreateRibbonExtensibility but rather do it by the book:

    public partial class ThisAddIn
        {
    
    
            private Ribbons _ribbon;
    
            protected override object RequestService(Guid serviceGuid)
            {
                if (serviceGuid == typeof(IRibbonExtensibility).GUID)
                {
                    return _ribbon ?? (_ribbon = new Ribbons(Application));
                }
                return base.RequestService(serviceGuid);
            }
        }

    • Marked as answer by Shailendra_G Monday, March 25, 2013 8:03 PM
    Saturday, March 23, 2013 8:08 AM

All replies

  • try to now override CreateRibbonExtensibility but rather do it by the book:

    public partial class ThisAddIn
        {
    
    
            private Ribbons _ribbon;
    
            protected override object RequestService(Guid serviceGuid)
            {
                if (serviceGuid == typeof(IRibbonExtensibility).GUID)
                {
                    return _ribbon ?? (_ribbon = new Ribbons(Application));
                }
                return base.RequestService(serviceGuid);
            }
        }

    • Marked as answer by Shailendra_G Monday, March 25, 2013 8:03 PM
    Saturday, March 23, 2013 8:08 AM
  • Thanks Damian. That worked wonderfully. This is what i added.

    private Ribbon _ribbon;
    
            protected override object RequestService(Guid serviceGuid)
            {
                if (serviceGuid == typeof(Microsoft.Office.Core.IRibbonExtensibility).GUID)
                {
                    return _ribbon ?? (_ribbon = new Ribbon());
                }
                return base.RequestService(serviceGuid);
            }

    But i have a small question though. Why this change?

    The only difference was in my development environment.

    In my old machine i had Windows XP/VS 2010/Office 2007. This addin worked fine on machines with Office 2010 as well as 2007.

    In my new machine i have Windows 7/VS 2010/Office 2010. This addin works fine on Office 2010 but not on Office 2007.

    Thanks for your help.

    Monday, March 25, 2013 8:02 PM
  • why this change - this question you should ask yourself - all documentation, etc. states that appraoch provided by me is the proper one for ribbon initialization. The one you used previously is a 'shortcut' that not always work, as you saw yourself.
    Tuesday, March 26, 2013 4:44 AM
  • why this change - this question you should ask yourself - all documentation, etc. states that appraoch provided by me is the proper one for ribbon initialization.

    This is just plain false. This documentation (from Microsoft) describes the method Shailendra_G used. You should be careful being arrogant with anything regarding Outlook add-in development, as there are surprises hidden everywhere.

    I've personally spent one month of calendar time and hours of support time remote connecting to one single of my 1000+ customers because of this faulty procedure of initializing the add-in.

    Still, thanks for pointing out the answer.

    Tuesday, June 18, 2013 9:39 AM