如何拦截内置的Officefunction区控件的点击

我想知道是否有可能检测到用户在Excel中单击了“页眉/页脚”button时,我可以在加载项的选项卡上显示一些自定义页眉/页脚相关的function区控件,并在用户不在页眉/页脚编辑模式。

是否有可能劫持这个button点击? 我以前看过应用程序劫持Excel Save。 我正在寻找与页眉/页脚button类似的行为。

我使用的是C#,Visual Studio 2012和Excel 2010.我使用Ribbon XML方法创build了自定义function区。

我发现工作的一种方式是使用function区XML(我不知道存在)中的<commands>部分。显然,这种机制允许您重新使用Excel固有的操作,但要注意并不是所有的控件都支持重新使用onActioncallback)

 <?xml version="1.0" encoding="UTF-8"?> <customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <commands> <command idMso="HeaderFooterInsert" onAction="testHeaderFooter"/> </commands> <ribbon> <tabs>... 

以及关联的事件处理程序:

  public void testHeaderFooter(Office.IRibbonControl control, bool cancelDefault) { MessageBox.Show("Testing."); cancelDefault = false; } 

这个链接非常有帮助:

http://social.msdn.microsoft.com/Forums/office/en-US/e1a60d16-053e-4697-b17c-b22d602f0400/intercept-the-onaction-event-of-a-gallery-element-of-excel- 2007-UI-带β=论坛VSTO