[英]Workbook.Close is not firing WorkbookBookBeforeClose Event in Excel Addins C#
在我的 ThisAddins.cs 中有 WorkbookBookBeforeClose 事件,并且在 Ribbon.cs 文件中有一个按钮事件,我写了 workbook.close (true,workbook.fullname,null) 它在处理多个文件时没有触发 WorkbookBookBeforeClose 事件。
调用 workbookBeforeClose 事件有什么要遵循的吗?
以下代码在我这边工作正常:
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.WorkbookBeforeClose += ApplicationOnWorkbookBeforeClose;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
// Catch the before close event
private void ApplicationOnWorkbookBeforeClose(Excel.Workbook wb, ref bool cancel)
{
MessageBox.Show("ApplicationOnWorkbookBeforeClose");
}
#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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.