Word 2007 VBA - 通过插件在新文档上加载宏

发布于 2024-11-27 18:59:51 字数 521 浏览 0 评论 0原文

各位早上好! :) 这就是我正在尝试做的事情。我有这个设计模板,我想将其添加到在 Word 2007 中创建的所有新文档中。此外,我还有一个 dotm 文件形式的插件,每次 Word 启动时都会加载该插件。该插件位于每台计算机的启动文件夹中。顺便说一句,这不是 COM 插件。

现在,我已经尝试了一些事情。首先,我尝试了 Document_NewDocument_Open 处理程序,以及 AutoExecAutoOpen 处理程序在插件 dotm 文件中。当我开始新文档时,Document_New 没有触发任何内容。 Document_Open 也没有。但是 AutoExec 确实触发了,但我无法在该触发器中应用设计配置文件,因为此时没有打开文档。

那么,我该怎么做呢?我根本不想弄乱normal.dot,所以我试图避免这种情况,并将所有代码保留在插件中,也许每个模板中保留一些宏。但仅此而已。我想保持干净。有什么想法吗?

Good morning good folks! :) So here's what I'm trying to do. I've got this design template that I want to add to all new documents that are being created in Word 2007. In additon, I've got an addin in the form of a dotm file that's loaded everytime Word starts. This addin is located in the Startup folder on each computer. This is not a COM addin btw.

Now, I've tried a few things out. First of all, I've tried the Document_New and Document_Open handlers, as well as the AutoExec and AutoOpen handlers in the addin dotm-file. Document_New did not trigger anything when I start a new document. Document_Open didn't either. But AutoExec did trigger, but I can't apply the design profile in that trigger because there is no document open at that point.

So, how do I do this? I do not want to mess with the normal.dot at all, so I'm trying to avoid that and keep all code in the addin and perhaps a few macros in each template. But that's it. I want to keep it clean. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小瓶盖 2024-12-04 18:59:51

您是否正在连接应用程序级别的事件?或者只是在文档级别?您需要对 Word 应用程序进行“带有事件”引用,以便捕获您感兴趣的事件。

请参见此处:http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm

Are you hooking in to events at the Application level? or just at the document level? You need a "with events" reference to the Word application in order to trap the events you're interested in.

See here: http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文