Jeff,
First a little background on the "mechanics" of Word macros. From the VBA
help topic on Auto Macros:
By giving a macro a special name, you can run it automatically when you
perform an operation such as starting Microsoft Word or opening a document.
Word recognizes the following names as automatic macros, or "auto" macros.
This help topic goes on to describe in some detail the various types of
"auto" macros, including the name of each of these special macros and when it
runs. The important one for you in this instance is:
Name: AutoOpen When it runs: Each time you open an existing document
Auto macros are created by either writing a procedure (sub) in any normal
code module using one of the keyword "auto" macro names, or by creating a
code module using one of these names and writing a procedure called "Main" in
this module. I would recommend reviewing the VBA help topics on this subject
for more information; search for "Auto Macros".
HOWEVER...
There are other ways to invoke a macro automatically. This is called
"event-based" code, which means it runs in response to something happening
(an event) in the Word environment. All sorts of things in Word have events
associated with them. For example, if you look at the code behind the
UserForm in your template, you'll probably see a procedure called something
like "Private Sub cmdOK_Click". This is code that's invoked in the "Click"
event of the "OK" CommandButton on the UserForm. (The name of the actual
procedure may be slightly different depending on what the name of the
CommandButton is, but you get the idea.)
What's important in your particular situation is understanding that
documents have events associated with them as well. These include a "Close"
event, a "New" event and (key for you) an "Open" event. MSFT was kind enough
to make the names of these events pretty self-descriptive, so I'm sure you
can work out what each one is.
Keeping in mind the basic code structure described in the discussion of
"auto" macros above and the way that "event-based" code is invoked, it
becomes apparent how the code you posted works: it runs in response to the
"Open" event of the document (Private Sub Document_Open). So in your case,
rather than having a AutoOpen macro you have a Document_Open macro that's
running whenever you open that particular document.
Now, having said all that, let's look at how to get around the problem
you're asking about.
The first place to look is at the process you're using to create a new
document from your template. You said that it's set up so that "Word opens
this *.dot file". I'm assuming that this means that you click "File |
Open..." and navigate to the template and actually _open_ it. This makes
sense since the code you posted is intended to run when the document (or in
this case, the template) is opened. And as Graham pointed out, this code is
actually pretty useless; all it does is create a new document from the
template - something that Word does natively, so there's really no need to
write code to do it.
However, this really isn't the best way to use a template because, as I said
above, Word will automatically create a new document from a template when you
click "File | New..." and select the desired template. And when this new
document is created, it doesn't contain any code - especially no "AutoOpen"
or "Document_Open" code. The code remains in the template, although if the
user has access to the template this code is still available for use in the
document - but that's a subject for another discussion.
What's missing from the information you have provided so far, however, is
the code that actually displays the UserForm you mentioned. I suspect that
there _is_ an "auto" macro lurking about somewhere in the template - most
likely an "AutoNew" macro (or possibly a "Document_New" macro) with code in
it that simply says something like:
Sub AutoNew()
UserForm1.Show
End Sub
(BTW, this is actually *really* sloppy code, but it works so I wouldn't
really worry about it.)
In the end, though, it doesn't really matter too much how the UserForm gets
displayed. The problem you're asking about is related to stopping the
UserForm from being displayed every time you re-open one of your documents.
I'd recommend doing a couple of things to see you can fix the problem.
NOTE: Before you do ANYTHING make a back up copy of your template as it
exists now.
First, try creating a new document from the template using the "File |
New..." process I discussed above. If the UserForm is displayed, then this
confirms that there is some sort of AutoNew / Document_New macro running
someplace. You could just stop there and change your process to use "File |
New..." instead of "File | Open...", but I suspect that won't entirely
resolve the problem - especially since the code you posted appears to be
doing something similar but you're still having problems.
Second, _open_ the template while holding down the Shift key (which should
stop the Document_Open macro from running) and then go into the VBA editor
and comment out the code in the Document_Open macro. You can do this by
either putting a single quote in front of every line of code or by selecting
the entire procedure (from Private Sub to End Sub) and clicking on the
"Comment Block" button. Then save the template and create a new document from
it using "File | New..." Finally - and this is the most important part of
this test - close the new document and re-open it and see if the UserForm is
still coming up. If things appear to still work OK, this confirms what Graham
said about the code being useless. It also resolves your issue; just leave
the code commented out and you should be good to go.
If you run into problems, post back. If all else fails, contact me at the
email address in my profile and I'll try to sort it out.
-----
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.