Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Self starting macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
EllenM - 01 Jun 2007 13:55 GMT
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
Bear - 01 Jun 2007 14:35 GMT
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
Signature

Windows XP, Word 2000

> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.