Excel VSTO 工作簿新事件 [英] Excel VSTO WorkbookNew event

查看:36
本文介绍了Excel VSTO 工作簿新事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Excel 2007 的一个 Excel 插件项目中,我需要检查创建新工作簿的事件.我还需要赶上 Workbook_Open 事件,我很容易做到了......在我对互联网的研究中,我发现了以下内容:

In one Excel Add-in project for Excel 2007 I need to check the event for the creation of a new workbook. I also needed to catch the Workbook_Open event which I did quite easily... On my research on the internet I found the following:

Application.WorkbookOpen 在打开任何工作簿时引发.电子表格将作为参数打开的工作簿传递给此事件.这个创建新的空白工作簿时不会引发事件.这而是引发 Application.WorkbookNew 事件.

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 事件...我遗漏了什么?

Unfortunately, I am unable so far to find the Application.WorkbookNew event... I am missing something?

输入应用程序后.自动完成为工作簿提供了一个很好的很长的事件列表(包括打开),但我找不到 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...

有什么想法吗?

谢谢!

推荐答案

您正在寻找 Application.NewWorkbook 事件.这是 VBA 参考.这是一个 C#/VB.Net 中的示例

You're looking for the Application.NewWorkbook event. Here's the VBA reference. And here is a an example in C#/VB.Net

我无法确认此信息的有效性,但我找到了以下说明(link):

I cannot confirm the validity of this information, but I found the following explanation(link):

NewWorkbook 事件是一个应用程序级事件.既然有也是同名的属性,Intellisense 不会向您显示此内容除非您显式地将应用程序对象强制转换为应用程序事件:

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);

事件处理程序:

    void ThisWorkbook_NewWorkbook(Microsoft.Office.Interop.Excel.Workbook Wb)
    {
        MessageBox.Show("New workbook" + Wb.Name);
    }

您尝试使用的程序仅在ThisWorkbook VBA 项目.它不能在直接 Excel 之外使用环境.

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.

这篇关于Excel VSTO 工作簿新事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆