>I want to dynamically add a macro to an active document. The Import method
>of
[quoted text clipped - 4 lines]
> a certain file is opened and remove the macro when when the file is
> closed.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
I want to intercept the some files being closed. I can intercept the "Close"
menu command, the "Exit" command, and the document close button. I can't make
that interception if the user closes the document by clicking the
application's window X button, which is actually the most likely way they'll
close the document. I'd rather not have a global interception in everyone's
template. That gets me to adding a routine to individual document's template.
Is that incorrect thinking?
> >I want to dynamically add a macro to an active document. The Import method
> >of
[quoted text clipped - 9 lines]
>
> What is this AutoExit macro supposed to be doing?
Jonathan West - 08 Jun 2007 10:19 GMT
>I want to intercept the some files being closed. I can intercept the
>"Close"
[quoted text clipped - 8 lines]
> template.
> Is that incorrect thinking?
Yes. if you want to be able to intercept the closing of a file, and in
certain circumstances ensure that the file is not closed despite the user's
command, then your only option is the DocumentBeforeClose event of the
Application object. This article will help you to learn to write application
event procedures
Writing application event procedures
http://www.word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm
Since this is an event of the Application object, it will fire whenever any
document is closed. So if you want to operate only on documents attached to
a particular template, you would have to check the AttachedTemplate property
of the document, and branch accordingly.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup