Hi Doug:
"On launch..." is the key. There are four "Auto-" series macro reserved
names.
The name "AutoOpen" runs whenever a document is opened.
The name "AutoNew" runs whenever a document is created.
If you want one that runs when Word is launched, you need to copy one and
name one "AutoExec()". That one runs when Word "executes" (i.e. Starts up).
For completeness: "AutoClose" happens when a document closes. "AutoExit"
happens when Word quits.
For a macro to "auto run" it MUST be named with the names I gave you, and it
MUST be in the "closest" template to the document, and it MUST be the only
macro so-named in that template. All three things must be true
Now, since you are getting so good at this, we should perhaps look into the
future when your automatic macros will become quite complex. At that stage,
you won't want to have to maintain four or five copies of the same code.
So you would take ONE copy of the code and name it as a "Function". Have a
look at the VBA help topics "Writing a Function Procedure" and "Calling Sub
and Function Procedures"
So edit "Sub AutoOpen()" to be "Private Function DougSetInitialView()"
Note: It is important to avoid naming conflicts when working with
Functions. That's why I added your name to the name. It doesn't matter how
long the name is: Word will turn it into a single integer when it compiles
the code. But weird things will happen if you get an undetected naming
conflict.
Then write a Sub like this:
Sub AutoOpen()
SetView
End Sub
Do that for the other four as well. That makes each of the Auto- macros
call the same function, so you only have to maintain one copy of the active
code.
I do this, because my AutoOpen macro is quite complex: a couple of
screenfuls of code, because it tests for and sets two private toolbars,
hides a couple of toolbars, disables a couple of toolbars that piss me off,
sets up a couple of styles, tests for and associates a couple of numbered
lists with the correct styles... It's be "growing" for the past ten years
In your instance, it is really not necessary because currently your macros
simply contain a single statement. But if you or anyone else comes to
maintain your code in years to come, they can see at a glance that all four
of them call the same function, instead of having to trace the code four
times to discover that all four do exactly the same thing.
Maintainability is well ahead of godliness if the person who gets to do the
maintenance is YOU
Cheers
John,
I created both macros - and they work if I select 'macro' then 'run.'
But isn't the idea that they should run automatically on launch?
thanks, dg
--
Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.
John McGhie <
[email protected]>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410