vba Excel Workbook Open 事件来自加载项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8419728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:38:48  来源:igfitidea点击:

Excel Workbook Open event from within an addin?

exceleventsexcel-vbaexcel-2007vba

提问by Austin

I am trying to trigger a macro to run when an Excel document is opened.

我试图在打开 Excel 文档时触发宏运行。

The problem I am running into is that all of my code resides within an Excel add-in. The Workbook_Open event doesn't work because I can't put the code in individual documents, I need it to reside in the add-in and run whenever any document is opened.

我遇到的问题是我的所有代码都驻留在 Excel 加载项中。Workbook_Open 事件不起作用,因为我无法将代码放入单个文档中,我需要它驻留在加载项中并在打开任何文档时运行。

Is there a way to modify the Workbook_Open event or is there another way to trigger a macro when a different document is opened?

有没有办法修改 Workbook_Open 事件,或者有没有另一种方法在打开不同的文档时触发宏?

回答by Charles Williams

You need to use an Application event. There is a good writeup on how to do this at Chip Pearson's site here.

您需要使用应用程序事件。这里是如何做到这一点的芯片皮尔逊的网站一个很好的书面记录在这里