如何禁用Excel内置的RibbonButton?
是否有可能将一个Excel中内置的RibbonButton 2010设置为enabled = false从Excel VSTO加载项?
我尝试了以下内容:
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; }
但是,这似乎只适用于右键单击上下文菜单。 而不是为了丝带button。
只能使用startFromScratch
function区UI属性禁用选项卡,而不能使用控件。 请参阅MSDN以供参考 。
另请参阅function区XML常见问题解答 ,了解Excelfunction区操作上的优秀资
不知道这是否对您有帮助,但是对于自定义function区,您可以使用function区XML实现getEnabled
callback。
在XML中:
<button id="btnMyButton" ... getEnabled="OnMyButton_GetEnabled" onAction="..."/>
在代码隐藏中:
public bool OnMyButton_GetEnabled(Office.IRibbonControl rControl) { // return true or false to enable or disable }
如果您需要强制调用这些callback(例如,由于其他事件而设置了启用/禁用状态variablesIRibbonUI.Invalidate()
则需要调用IRibbonUI.Invalidate()
方法。
顺便说一下,function区devise器界面(在VS 2010上)似乎没有提供实现getEnabled
callback的能力。