Run autoexec macro on loading a template?

A

and

Hi,

I am looking for a way to run a "Sub AutoExec" on loading the template
that contains the macro (by checking a template in the Tools > Templates
and Add-ins dialog box OR by placing the template in the Startup folder
of Word).

How can this be done?
 
J

Jonathan West

Hi and

If you place the sub in a standard module, and ensure it has no arguments,
then it will run automatically when the template is loaded as an add-in,
provided that the macro security settings in Word permit the code to run
 
P

Peter Hewett

Hi and

I think you've just said it all, you create a sub called AutoExec! Actually
there are two ways of doing it:

- Create a sub called AutoExec: "Public Sub AutoExec()". This must be in a
module not a UserForm or a class.
- Create a Module called "AutoExec" anad a sub named Main:
"Public Sub Main()"

Place either one of these procedures (macros) in your template and it will
execute when the Add-In loads. That's either when Word starts (if it's in one
of Words startup folders) or when you load the Add-In.

HTH + Cheers - Peter
 
A

and

Thanks Peter and Jonathan,

It didn't work because I had the template simply opened as a file to
edit the vba code, but when I closed the template and loaded it manually
by checking it in the dialog box, it worked alright.



-------- Original Message --------
 
G

Graham Mayor

An autoexec macro works exactly as you describe ie if the containing
template is located in the Word or Office startup folder it will run when
the template is loaded, when Word is started.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 

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