工作簿.Close未在Excel加载项C#中触发WorkbookBookBeforeClose事件



在我的ThisAddins.cs中,我有WorkbookBookBeforeClose事件,并且在Ribbon.cs文件中有一个按钮事件,我在其中编写了workbook.close(true,workbook.fullname,null(,它没有启动使用多个文件时发生WorkbookBookBeforeClose事件。

调用工作簿BeforeClose Event有什么需要遵循的吗?

以下代码在我这边运行良好:

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
}

相关内容

  • 没有找到相关文章

最新更新