[英]Excel VSTO WorkbookNew event
In one Excel Add-in project for Excel 2007 I need to check the event for the creation of a new workbook. 在Excel 2007的一个Excel加载项项目中,我需要检查事件以创建新工作簿。 I also needed to catch the Workbook_Open event which I did quite easily... On my research on the internet I found the following:
我还需要抓住Workbook_Open活动,我很容易做到这一点......在我对互联网的研究中,我发现了以下内容:
Application.WorkbookOpen is raised when any workbook is opened.
在打开任何工作簿时引发Application.WorkbookOpen。 Excel passes the Workbook that is opened as a parameter to this event.
Excel将作为参数打开的工作簿传递给此事件。 This event is not raised when a new blank workbook is created.
创建新的空白工作簿时不会引发此事件。 The Application.WorkbookNew event is raised instead.
而是引发Application.WorkbookNew事件。
Unfortunately, I am unable so far to find the Application.WorkbookNew event... I am missing something? 不幸的是,到目前为止我无法找到Application.WorkbookNew事件......我遗失了什么?
After typing Application. 输入应用程序后。 the autocomplete provides a nice and long list of events for the Workbook (Open included), but I can't find the WorkbookNew event...
自动完成为工作簿提供了一个很好的长事件列表(包含Open),但我找不到WorkbookNew事件......
Any ideas? 有任何想法吗?
Thank you! 谢谢!
You're looking for the Application.NewWorkbook event
. 您正在寻找
Application.NewWorkbook event
。 Here's the VBA reference . 这是VBA参考 。 And here is a an example in C#/VB.Net
这是C#/ VB.Net中的一个例子
Edit: 编辑:
I cannot confirm the validity of this information, but I found the following explanation (link) : 我无法确认此信息的有效性,但我发现了以下解释(链接) :
The NewWorkbook event is an application level event.
NewWorkbook事件是一个应用程序级事件。 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:
由于还有一个同名的属性,除非您将应用程序对象显式转换为应用程序事件,否则Intellisense不会向您显示此信息:
((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.
您尝试使用的过程仅在ThisWorkbook VBA项目中有效。 It can't be used outside the immediate Excel environment.
它不能在直接Excel环境之外使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.