Template still opens after DOC created?

L

Larry

Man, just when you think you are getting to know how to program around WORD,
something else happens to show you how little you really know!

I created a template (mentioned in another post earlier today) that will be
used as a form for travel requests.

When I double-click on the template, it opens and I can modify the document
then when I close WORD it asks me to save the new document. I do, but then
it asks me if I want to save changes to the template too! It shouldn't do
this!!!! (Is it b/c I load dropdown data in the NEW and OPEN events?)

But, then after WORD is closed, when I open the document I just saved. Make
changes, and close it, it again asks me if I want to save changes to the
template!??!! I didn't even open the template at this point, it was just
the document created from the template!

I then opened the document again, and looked in the folder where the files
are located, and sure enough, there is a temp WORD file for both the
document AND the template!

What is going on????

Help please!!!
 
P

Peter Hewett

Hi Larry

A Word document is ALWAYS bound to an underlying template. In this case
your document is bound to the template it was created from. What this means
in practice is that when you open your document Word opens the template as
well. The reason for this is that there are a number of things stored in
the template but not the document, these are:

1. Macros
2. Toolbars
3. AutoText

So if you change any of the above either manually or programatically then
the changes are actually being made to the template. So when you close the
document Word is also closing the template and since you've changed it,
Word asks you if you want to save the changes to the template!!!

Styles confuse the issue nicely by being defined in both the document AND
the template. You can set a document up so that changes made to styles in
the template automatically update the document. You can also set things up
so that changes made to styles in the document update the template!!

I hope this does not confuse you too much. The best way to see what's
happening is to create a test template and then create some documents using
the template and make changes to the above items to see exactly what's
happening.

HTH + Cheers - Peter
 
L

Larry

You did a good job explaining why templates are tied to documents, but do
you know how I can get my code to only update the document, not the
template? That's not what was intended.

At this point, if I don't make this a template (which is the way I am
leaning) it works fine. So if I have to, I will do away with the template
idea all together.
 
P

Perry

From the perspective of code being executed and listed in a template:
Look for the difference in usage of ThisDocument versus ActiveDocument
Whereas, ThisDocument will affect the template, ActiveDocument will affect
the document that is currently active.

Examples:
vba) ThisDocument.Save
will save the template the code is running from
vba) ActiveDocument.Save
will save the currently active document, it won't save the template

Looking at it from the perspective of code being executed and listed
from a document, following statement will affect the template:
ActiveDocument.AttachedTemplate

Examples:
vba) ActiveDocument.AttachedTemplate.Save
will save the template, the document was based on.
vba) ActiveDocument.Save
will save the document, the template is left untempered.

Krgrds,
Perry
 
C

Charles Kenyon

If you are creating or changing user interface items in your template
(rather than having those changes already in the template) you are changing
it. You can put the following statement in your code after the code makes
such changes to avoid triggering the alert:

ThisDocument.Saved = True

Unless the changes to the interface are different each time you use the
template, my preference is to make the changes (adding / changing toolbars,
etc.) in the template itself once, either by code or manually. Then get rid
of the code that makes the changes. Save the template. The changes will be
reflected in the interface when your template is being used.

Note "ThisDocument" is the template while "ActiveDocument" is the document
created from the template.
--

Charles Kenyon

Word New User FAQ & Web Directory:
See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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