There is one case for using the AutoOpen macro. Imagine you are loading 5 templates and they all contain the Document_Open() event handler. Sure, they will all run, but in what order? Implementing code through the AutoOpen (it must be in the Normal.dot!) will ensure that your code will run first. Note: if there's an existing AutoOpen, you must plug into it.
----- Martin Seelhofer wrote: -----
Hello NG
Please, can you clarify this...
... or I have been incrdedibly lucky these past 2 years.
From my point of view, the "AutoOpen"-approach is deprecated and
should not be used anymore, since it does not follow the more object-
oriented approach of Document_Open. So I don't think you have been
too lucky in the past ;-)
The reason why the Document_Open-Event is not fired in Bruce' case
I suspect to be a security issue (value 'High' in Tools - Macro -
Security?)...
However, the Document_Open-event-handler IS the right way
to do it. In my opinion, that is ;-)
I have never included a WithEvents procedure in a class module...
What do you mean by "Heavy-handed"?
Well, the WithEvents-stuff is a way to attach event handlers to an
object variable. However, you only need this, if your object does
not already have a corresponding class-module attached. Since
there is one (a class module) for the Document-Object (ThisDocument),
you don't need the WithEvents-thing for that purpose. But note
that you can use WithEvents for other objects such as e.g. the
Application object. This way, you can attach yourself (or your
macros, respectively) to events fired by e.g. Word itself. For the
latter, these events include e.g. WindowActivate, WindowSize,
DocumentBeforePrint and many others...
To get to know this method, add a module-level variable to
your code using WithEvents like this:
Public WithEvents wd As Word.Application
.... and watch the object dropdown which will be extended to
include the newly created variable wd. Choose it to see all the
available Events in the 'procedure'-dropdown.
Ah yes: And don't forget to initialize your object variable
somewhere in your code e.g. in the Document_Open-Event-
Handler
Have fun,
Martin