Microsoftfunction区button从外接程序执行function
好的,所以我做了大量的search,试图find关于这个话题的信息,而且我几乎空手而归。 也许我不是在寻找正在尝试完成的正确术语。
我的问题是,我已经写了一个MS Excel加载项的function,我遵循微软的指示作为一个起点,但他们的教程有代码执行每次用户保存文档。 我的目标是在我devise的function区上有一个button执行此function,而不是保存button。
这是我遵循自己启动的Microsoft文章: https : //msdn.microsoft.com/en-us/library/cc668205.aspx
我也在这里发现了这个问题,但是它没有足够的细节来弄清楚如何为自己实现解决scheme: 如何将一个function区button连接到Excel加载项中定义的函数?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using Excel = Microsoft.Office.Interop.Excel; using Office = Microsoft.Office.Core; using Microsoft.Office.Tools.Excel; namespace ExcelAddIn1 { public partial class ThisAddIn { void FormatTime(Microsoft.Office.Interop.Excel.Workbook WB, bool SaveAsUi, ref bool Cancel) { /////MY FUNCTION BODY HERE////// } private void ThisAddIn_Startup(object sender, System.EventArgs e) { } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } }
提前感谢你的帮助。
VSTO提供了两种创build自定义用户界面的方法:
-
function区devise器 – 请参阅演练:使用function区devise器创build自定义选项卡 。
-
原始的XML标记 – 演练:使用function区XML创build自定义选项卡 。
在这两种情况下,您都可以使用Globals.ThisAddin
属性来访问加载项属性和方法,该属性返回加载项类的实例(在上面列出的代码中显示)。
通常,您可以使用Globals.ThisAddIn.Application来访问应用程序级别和文档级别的UI。 我希望这个链接可以帮助。 下面是一个button添加到工作表的示例,如下所示:
Globals.Factory.GetVstoObject( Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets[1]) .Controls.AddControl(button, selection, buttonName);
好像