在一个 Excel 2007 的 Excel 加载项项目中,我需要检查创建新工作簿的事件。我还需要捕捉 Workbook_Open 事件,我很容易就做到了......在我对互联网的研究中,我发现了以下内容:
Application.WorkbookOpen is raised when any workbook is opened. Excel passes the Workbook that is opened as a parameter to this event. This event is not raised when a new blank workbook is created. The Application.WorkbookNew event is raised instead.
不幸的是,到目前为止我无法找到 Application.WorkbookNew 事件......我错过了什么?
键入应用程序后。自动完成为工作簿(包括打开)提供了一个很好的长事件列表,但我找不到 WorkbookNew 事件...
有什么想法吗?
谢谢!
最佳答案
您正在查找 Application.NewWorkbook 事件
。 Here's the VBA reference .这是一个 example in C#/VB.Net
编辑:
我无法确认此信息的有效性,但我找到了以下解释 (link) :
The NewWorkbook event is an application level event. Since there's also a property of the same name, Intellisense won't show this to you unless you explicitly cast the application object to the application events:
((Excel.AppEvents_Event)ThisApplication).NewWorkbook += new Microsoft.Office.Interop.Excel.AppEvents_NewWorkbookEventHandler(ThisWorkbook_NewWorkbook);
The event handler:
void ThisWorkbook_NewWorkbook(Microsoft.Office.Interop.Excel.Workbook Wb) { MessageBox.Show("New workbook" + Wb.Name); }
The procedure you were trying to work with is only valid in the ThisWorkbook VBA project. It can't be used outside the immediate Excel environment.
关于c# - Excel VSTO 工作簿新事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12901146/