Self starting macro

E

EllenM

Hello,
How do you get a macro to self-start the moment that a particular document
is opened?

Thanks in advance for your help,
Ellen
 
B

Bear

Ellen:

Open the document, then press Alt+F11 to open the VBE. Open the document
project, open the Microsoft Word Objects folder, and double-click
ThisDocument to opent its code window.

Change the Object list (the left-hand drop-down) to Document, and the VBE
will create a sub called Document_New. Look at the other options in the
Procedure list (right-hand drop-down). One of these is for the Document_Open
event and sub.

You could put your code in the Document_Open sub of the document. Note that
the template opens (invisibly) every time a document based on the template
opens. So it seems to have the same behavior re when it gets started.

Similar prodecures are available in the template on which the document is
based. It might make more sense to put the macro in the Document_Open sub in
the template. That would minimize the number of instances of the code,
provide smaller documents, etc.

Document_New in the template, by the way, runs whenever the user creates a
new document from the template. Also handy at times.

Finally, Word "autoruns" macros stored in a Module IF you give the macros a
special name:

AutoNew
AutoOpen
AutoClose

Check the Word MVP site for more articles on this kind of application.

http://word.mvps.org/faqs/macrosvba/PseudoAutoMacros.htm

Bear
 

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