1
votes

I have simple VSTO Excel 2013 Application level Add-in with custom Ribbon, which includes toggle button and checkbox. If I open two files (workbooks) I can see that the Ribbons do not preserve their state across multiple windows, meaning if I click on checkbox or toggle button on Second workbook the same checkbox state is shown on a first workbook and vise versa. I found an article which describes a similar situation for outlook : https://www.add-in-express.com/creating-addins-blog/2013/01/30/preserve-outlook-ribbon-controls-state/ but unfortunately the Inspector window event is not available in Excel. Any idea on how to deal with it?

2
the discussion here social.msdn.microsoft.com/Forums/windowsserver/en-US/… might give you more information about this issue.Philippe.H
Hi, thanks for the link I've found it already previously, but according to it there is no joy for this problem :) Hoping to find a workaround to this issueJim
I proposed another simple solution here : stackoverflow.com/questions/23418686/…Malick

2 Answers

1
votes

You need to use callbacks instead of attributes in the Ribbon XML. Also when a user changes the active window you need to call the Invalidate/InvalidateControl method of the IRibbonUI interface to force Office applications (Excel in your case) call your callbacks for the current state of controls. It's pretty easy...

You can read more about the Ribbon UI (aka Fluent UI) in the following series of articles in MSDN:

Also you may find the following ones helpful:

1
votes

I tried a sample with a toggle button with toggle on and then switched to another workbook the toggle button doesnt persist. But then if you stored the pressed value in a variable and return that on getPressed callback of a toggle button it worked.

Ribbon.xml

    <?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon>
        <tabs>
            <tab idMso="TabAddIns">
                <group id="group1" label="group1">
                    <toggleButton id="toggleButton1" label="toggleButton1" size="large" getPressed="buttonPressed" onAction="buttonAction"/>
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

Ribbon.cs

private bool isButtonPressed = false;
    public void buttonAction(Office.IRibbonControl control, bool isPressed)
    {
        isButtonPressed = isPressed;
    }
    public bool buttonPressed(Office.IRibbonControl control)
    {
        return isButtonPressed;
    }