Template reference lost after new document created and closed

P

Peter McLennan

I have one master template that I copy in the contents from one of 5
documents. The content of the copied document is then what the user
enters information into. The template has code that is called at
startup, from the toolbar, and when the user closes the template.

Everything works fine except when the user closes the document, and
then re-opens the document, there is no link to my master template
only a reference to Normal.dot.

Is it something to do with me copying an entire document into the
master template?

Pain in the neck because it appeared everything was working fine until
I re-opened a document I had just created.

Of course I did not re-open a document after two days of coding had
lapsed!!!

The reason behind this design is so that there is one block of code
that I edit instead of copying the code to all five templates.

Any answers greatly recieved because it looks like I will have to lose
two days work and revert back to the 5 templates all with identical
code.
 
T

Tom Winter

You might want to think about using a global template, which is a .DOT file
stored in Word'd startup folder. (Look in TOOLS | OPTIONS | FILE LOCATIONS |
Startup Folder). Your code could then be accessed any time.

But back to your question.

How is the "document" created? Is is based on one of these templates? If
it's just a blank document based on normal.dot, you need to switch the
attached template. Use Document.AttachedTemplates.

Hope that helps!
 
P

Peter McLennan

Thanks Tom,

Unfortunately I may not have been clear enough.

I have a template called Mins.dot. It has nothing in except code. I
have 5 documents that are formated and styled.

When Mins.Dot starts, it copies one of the 5 documents into the new
document created by Mins.dot.

The new document has a reference to Mins.dot for the entire session,
and all works fine.

Close the document and re-open it, and the reference to Mins.dot is
lost.

I have tried code in the close SUB to get the document path, close it,
re-open it, and then set ActiveDocument.AttachedTemplate =
"C:/Templates/Mins.Dot" ('/' should be the other way around but this
editor is throwing a funny character.

The line ActiveDocument.AttachedTemplate = "C:/Templates/Mins.Dot"
throws an error "The document template is not valid".

I have also tried the line while the document is open, and I get the
same error.

HOWEVER!! If I try any other template it does not throw the error. I
will try and add a style into Mins.dot that is not used and see if
that solves the problem. Because Mins.DOT has no styles in it its
blank.
 
P

Peter McLennan

Here is the situation.

I can save the document to ANY path except the MyDocuments folder. If
I save it to the MyDocuments folder the template detaches from the
document. If I save it to ANY other folder it retains the link to the
template.

Now the reason behind it all!!!

1. The MyDocuments folder has an old version of the template

2. If it is the exact same version, it attaches to the template in the
same path, rather than the original location.

3. If it is an OLD template version, Word stuffs up and does not
attach to the original template, it tries to attach to the one in the
same path as the document, and fails THEN does NOT attach to the
correct template that is in a different folder.


Now I know this situation should not come up, however I was about to
throw 3 days worth of work because it appeard my template was
corrupted in some way. I had a lot of junk files in MyDocuments and
in the multipudes of files, was an old version of the template.


Now you could use this to your advantage if you wanted to create
documents that detached from their templates, but heck you can do that
anyway with the AttachedTemplate object.

Well I'll be!!!!!!!!
 

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