Running a macro upon opening a template

M

Malcolm Smith

A template or a document based on a template?

In both cases the Document_Open event will be used, but if you want to
only run the event if it is a document and not the template itself then
what I do is to test the name of the ActiveDocument and if it has ".dot"
at the end I don't execute any more:

Again, watch out for the compile errors, if any.


Private Sub Document_Open()

if instr(1, ActiveDocument.Name, ".dot", vbCompareText) = 0 then

' Do processing here of the document.

end if

Ens sub


Regards
Malc
www.dragondrop.com
 
C

Chad DeMeyer

Safer than testing the name, which can be changed in Windows (and yes, I
have seen funky names like "somefile.dot.doc" and "somefile.doc.dot") is to
use
If ActiveDocument.Type = wdTypeTemplate Then Exit Sub

Regards,
Chad
 

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