Is a Class Module the answer?

A

AndyE

I have atemplate with New Document and Open Document events. I intend
distributing the template to allow users to create documents from it (works
fine). I also want the created documents to run the DocOpen event when they
are re-opened, but that doesn't work even if the template is installed. It
only runs when the template file is opened.
I have been trying a WithEvents class module, but that doesn't seem to run
from the child documents either. I have the class module in the template
project. Is this the right place? Can I even use this approach?

AndyE
 
A

Anne P.

In the VB Editor, double-click This Document in your template. Add the
following code:

Private Sub Document_New()
'your code here
End Sub

Private Sub Document_Open()
'your code here
End Sub

Whenever a document that was created from your template is opened, any code
put under Document_Open will run.

Anne P.
 
J

Jezebel

If you want to use the WithEvents approach, you need to --

a) put the event code in a class module, that contains a module-level
WithEvents declaration, and

b) instantiate an instance of the class module when Word starts, typically
using an AutoExec function.
 
A

AndyE

Thanks Jezebel. I was missing the AutoExec function. Where should that be
stored? In the template?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top