Excel Add-in being wrongly rendered RRS feed

  • Question

  • Hi,

    I've developed Add-ins for Word, PowerPoint and Excel. My Add-in has a Ribbon with one button that changes due to the context of the document.

    As I read in the documentation the Add-in is an application based Add-in, means that the ribbon is one for all documents opened in the same application. However, I noticed that refreshing the button of the Ribbon affects only the active window of the application (which is exactly what I need). I simply register the "Application.WindowActivate" event and repaint the button according to the active document at the moment.

    The issue is that in Excel this method doesn't work properly for me. Whenever I switch focus between 2 Excel workbooks (which in Office 2013 are situated in separate windows), both workbooks are repainted with the new value of the button. If I switch focus by selecting the title bar of the window, everything works as expected but if I change focus by clicking on the cells area, both buttons are refreshed.

    I've created a dummy Add-in to demonstrate the issue:

            Ribbon1 m_Ribbon = new Ribbon1();

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
                Application.WindowActivate += new Excel.AppEvents_WindowActivateEventHandler(Application_WindowActivate);

            void Application_WindowActivate(Excel.Workbook Wb, Excel.Window Wn)
                m_Ribbon.group1.Label = m_Ribbon.group1.Label + "1";

            protected override Microsoft.Office.Tools.Ribbon.IRibbonExtension[] CreateRibbonObjects()
                m_Ribbon = new Ribbon1();
                return new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { m_Ribbon };

    If you run this code, you'll notice that on both windows the label of the button is updated with "1". notice that if you have more then 2 Excel workbooks open, only the last 2 touched are refreshed. In addition if the focus is moved from one workbook to another application and only then to the second workbook, everything works as expected.

    Can you please assist?



    Sunday, November 22, 2015 7:07 AM

All replies

  • Hi Misha,

    I made a test with your code, but I got error “Object reference not set to an instance of an object” when the code in Application_WindowActivate. Could you share us details steps to reproduce your issue?

    Based on your description, it seems you want to change the group label at runtime. But why did you want to change it in Application_WindowActivate? In my option, this event would fire when any workbook windows is activated. It means when you workbook is activated, your group label would change, and your issue would be expected behavior. Without enable testing it, I could not reproduce more than 2 excel workbooks open, only the last 2 touched are refreshed.

    For a general suggestion, I suggest you use getLabel call to set the label.
    # Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 23, 2015 6:26 AM