How can I disable the inline RibbonButton?

Is it possible to set excel 2010 embedded in RibbonButton to enabled = false from excel VSTO Add-In?

I tried the following:

CommandBarControls controlls=Globals.ThisAddIn.Application.CommandBars.FindControls(MsoControlType.msoControlButton, 7374, null, false);
/// 7374 is the office control id of the control I want to access

foreach (CommandBarControl control in controlls)
{
    control.Enabled = false;
}

      

But this only seems to work for the right click context menu. And not for ribbon buttons.

+3


source to share


2 answers


You can turn off tabs rather than controls if you are not using the startFromScratch

Ribbon UI attribute . See MSDN for help .



Also see the XML Ribbon FAQ for good resources when handling Excel Ribbon.

+4


source


Not sure if this will help you, but for a custom feed, you implement the callback getEnabled

using XML feed.

In XML:

<button id="btnMyButton" ... getEnabled="OnMyButton_GetEnabled" onAction="..."/>

      

In code:



public bool OnMyButton_GetEnabled(Office.IRibbonControl rControl)
{
  // return true or false to enable or disable 
}

      

You need to call the method IRibbonUI.Invalidate()

if you need to force these callbacks to be called (for example, when your on / off state variables are set due to some other event).

Btw, the Designer Ribbon interface (as of VS 2010) doesn't seem to provide a way to implement a callback getEnabled

.

+2


source







All Articles