You put it in the Document_Open Event of either the document or the template.
In the ThisDocument Module (of either document or template as desired) select Document from the lft hand dropdown and Open from the right hand dropdown and put your code in the generated skeleton procedure.
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
With due (and HUGE) respect to Tony, it is not quite that simple.
There is an order for macros to run when a document opens. So depending on what exactly you want to happen, AND WHEN, there are other considerations. Here is the order in which Word fires automatic opening procedures.
1. the DOCUMENT AutoOpen macro
(in a standard module)
2. the TEMPLATE Document_Open macro
(in the template ThisDocument module)
3. the DOCUMENT Document_Open macro
(in the document ThisDocument module)
As you can see, putting Document_Open in the document TEMPLATE ThisDocument will fire before a macro in the DOCUMENT ThisDocument - but an AutoOpen macro in the DOCUMENT trumps everything.
Also note that even if there is an AutoOpen in the template, IF there is an AutoOpen in the Document, not only does it run first, but it causes Word to ignore any existing AutoOpen macros in either the template that created the document, AND any AutoOpen macros in Normal.Dot as well. Again, an AutoOpen in a document trumps everything.
I've tried your suggestions but, I can't get them to work. I'm trying to set a document up so that it will automatically print and then close without saving.
I'm missing something here!! You want a document when opened to automatically just print and close? So you never want to change it again?
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
I am with Tony on this. Could you tell us exactly what you want to happen. Are you possibly trying to (and I am throwing a wild guess out here) automate printing a NUMBER of files? You just want to print them and nothing more? Remember you asked about automating a macro. We assumed you wanted a macro that ran when the document opened. Perhaps this is not exactly what you want.
If you want to simply print and close a document - then state that is what you want to happen. This is a different action from what we were describing.
You don't have to actually OPEN a file to print it. In Word, Click on FILE, then OPEN. Click once on the file you want, then click on TOOLS..then PRINT.
This option lets you preview the file before printing (if you have that option selected in the OPEN dialog box).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.