c# - Excel VSTO 工作簿新事件

标签 c# excel vsto

在一个 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/

相关文章:

c# - 检查是否选择了整张纸?

c# - 有没有理由不将 "1"类与小型 VSTO 加载项一起使用?

c# - Asp.net调用C#层调用Managed C++调用Native C++

excel - 在 Excel 工作表之间粘贴时运行缓慢的宏和避免选择

c# - SharePoint Lists.asmx UpdateListItems SET Field1=NewValue WHERE Field1=OldValue(按要更新的字段过滤)

vba - 在新工作簿中复制 Excel 主题颜色

vba - 使 VBA 表单文本框仅接受数字(包括 +、- 和 .)

c# - 在 Excel 2003 中调整编辑栏的大小

javascript - jQuery 调用 Web API 不起作用

c# - FlowPanel 垂直滚动