1

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?

Jim
  • 2,760
  • 8
  • 42
  • 66
  • 1
    the discussion here https://social.msdn.microsoft.com/Forums/windowsserver/en-US/a3dade87-1df7-46ec-8876-437194d7553e/how-to-reference-the-correct-workbook-from-a-control-in-a-ribbon-callback?forum=exceldev might give you more information about this issue. – Philippe.H May 15 '15 at 12:10
  • 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 issue – Jim May 15 '15 at 12:41
  • I proposed another simple solution here : http://stackoverflow.com/questions/23418686/excel-2013-vsto-ribbon-edit-controls/33153525#33153525 – Malick Oct 15 '15 at 16:18

2 Answers2

1

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:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hi Eugene, I saw your answer previously, however I have created an Ribbon in Designer and unless I am totally wrong the Issue is related more to In-Active rather to Active window. In particular case when the Active window Ribbon state changes it also reflected on the In-Active window. If it is not big trouble Could you pls put few lines here as it is common issue and will help all of Add-In devs. Thanks – Jim May 15 '15 at 13:21
  • It seems I need to describe it in a blog post in depth... There is no way to update the in-active state of ribbon controls. You have no control over that. The only possible way is to use callbacks when you switch to another/this workbook. – Eugene Astafiev May 15 '15 at 13:44
  • I see, so basically we are stuck with this issue I do have proper Activation and Enabling state on Active Window Ribbon State, so the issue is more like a Cosmetic one rather functional. – Jim May 15 '15 at 13:49
  • Yes and its fine in versions prior 2013, since we don't have an pseudo-SDI. however it looks unacceptable in 2013 where the feeling is that each window is pure SDI. – Jim May 15 '15 at 14:13
  • The fact is that Office decides when to call callbacks. You may just request it when required. – Eugene Astafiev May 15 '15 at 14:18
1

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;
    }
Kiru
  • 3,489
  • 1
  • 25
  • 46