Word 2007 VBA - Load macro on Document New via Addin
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 every开发者_Go百科time 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?
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
精彩评论