Issue with Ribbon Invalidation RRS feed

  • Question

  • Hello,

    I have created an Excel ribbon using VSTO (xml+C# code). I have few Buttons which needs to be enabled only under certain conditions. 

    I check the conditions and use IRibbonUI.Invalidate() to enable those buttons. It works perfectly alright but the problem is that those buttons go back the original state (which is diabled) when the MS Excel is closed/restarted. 

    I would like to have the buttons which retain the status of the previous excel session. Is this possible?.

    The xml file has getEnabled call back which calls the "RibbonControlEnable" function which basically return a bool (true or false) depending on few criteria.

            private Office.IRibbonUI ribbon;
            private bool SuperUserEnabled= false;
            public Ribbon()
            public string GetCustomUI(string ribbonID)
                return GetResourceText("MyUtilities.Ribbon.xml");
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
                this.ribbon = ribbonUI;
            public void RibbonActions(Office.IRibbonControl control)
                switch (control.Id)
                    case "Button1":
                        // some code
                    case "Button2":
                        //Some code

    I have another function to invalidate the ribbons where I check a criteria and invalidate the ribbon using the code below


    Everything works as intended but the status of the previous excel session is not retained for the next session.

    What I am struggling to understand is why the refreshed ribbon is not retained for the next excel session. Is there a way to acheive it?

    Best Regards,


    Tuesday, June 23, 2020 6:02 PM

All replies

  • You need to use the IRibbonUI.Invalidate or IRibbonUI.InvalidateControl methods for that. For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.

    Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    If you want to get your settings persisted you need to save them somewhere, for example, to a file on the disk. Next time when the Office application is started and ribbon callbacks are invoked you can read values and return appropriate values in the callbacks defined.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, June 23, 2020 6:48 PM
  • Hi Eugene,

    Do you have a line of code for the same. I am unable to understand why my code is not working. I recently upgraded to C# from VB.NET. The ribbon.Invalidate() was working perfectly well under VB.NET. I don't understand if I have missed something. 

    As you can read my description above. I have already used the below code inside the ribbon class to invalidate the ribbon. 

    Many Thanks,


    Tuesday, June 23, 2020 7:04 PM
  • Did you try to debug the code? Is the Ribbon_Load event handler fired at least?

    By default, if a VSTO Add-in attempts to manipulate the Microsoft Office user interface (UI) and fails, no error message is displayed. However, you can configure Microsoft Office applications to display messages for errors that relate to the UI. You can use these messages to help determine why a custom ribbon does not appear, or why a ribbon appears but no controls appear.

    To show VSTO Add-in user interface errors

    1. Start the application.

    2. Click the File tab.

    3. Click Options.

    4. In the categories pane, click Advanced.

    5. In the details pane, select Show VSTO Add-in user interface errors, and then click OK.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, June 23, 2020 9:05 PM