Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word template references disappear

Status
Not open for further replies.

DonnaB

Programmer
Apr 23, 2001
34
0
0
AU
Hi there,

Whenever I try to create a reference to Normal from a template, it disappears. What I do is this:

Create a new template in Word
Open VBA (ALT-F11)
Select Tools -> References
Select checkbox next to Normal, click OK

The reference then appears in the Project Explorer window.

However, if I close the template and re-open it, the reference has been removed.

Does anyone know how to make this stay?

Cheers,
Donna.
 
I am using Word 2002 (10.6764.6735) SP3

I have just realised that the reference is only removed if I create the template from within Word. If I create one in Windows Explorer by just saying "new word document" and calling it Test.dot, the reference to Normal is put in automatically and never disappears.

Does anyone know what might cause this?!

Thanks in advance,
Donna.
 
You may try this:
ActiveDocument.AttachedTemplate = NormalTemplate

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV! This has been resolved!

Donna.
 
Hi Donna,

You are confusing documents and templates.

Documents should have a .doc suffix.
Templates should have a .dot suffix.

However, changing the suffix does not change the type.

All documents have an attached template (Normal by default).

Templates can not have an attached template - if you try and attach a template to a template it will fail (so I don't understand how PHV's suggestion has helped you).

Any document or template can have a reference to any other document. However Word will not save the reference unless it is used. That is why your attempt to add a reference to Normal to your .dot template fails.

Having a reference will force the referenced file to be opened but Normal is always opened anyway. So what are you trying to achieve by adding the reference to Normal to your template?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi Tony,

Thanks for your information, it's always good to learn more about the intricacies of Word.

I was trying to deploy a macro that I was written partly by myself and partly by an external consulant. It does a mail merge then calls a soap service to hook into Cache code to upload the mail merge results to a document management system. It works fine in the template that it was developed in, however, when I tried to import the forms, classes, etc into a new template, the merge kept failing. Unfortunately this is the part that was not written by myself, so I had a tough time trying to find the bug.

I noticed that the base template (which works) has a reference to Normal (don't ask me how, I have no idea, but it does). So this made me think this was the problem.

I've since realised that the reference to Normal is not required by the template, but there was a line of code which was wrong.

Instead of saying:
ThisDocument.MailMerge.ShowWizard 1

It should say:
ActiveDocument.MailMerge.ShowWizard 3

Of course, this worked okay in the base template because ThisDocument was the Document1.doc (i.e. the doc that opens when you double click on the template). However, in the new templates, ThisDocument actual referred to the template, not the document, so the datasource was loaded into there instead of the document.

Hmm, lots of looking around to find that little bug, but hey, got there in the end!

:)

Thanks again for your help!

Donna.
 
You are still confusing documents and templates - except now the confusion is on the code modules therein.

ThisDocument is kind of a special code module.

ALL documents have a ThisDocument code module, including templates (.dot files), which are, in fact, documents as well.

The difference being is that a document (.doc file) generated, or cloned, from a template has a pointer back to the ThisDocument code module of the template.

It has its own ThisDocument, but ALSO can run code that is in the ThisDocument code module of the template.

You can see for yourself. Put the following into the ThisDocument module of normal.dot.

Code:
Sub TryMe()
MsgBox "Hello, I am in the ThisDocument of normal.dot."
End Sub

Close Word. Normal.dot will save...hopefully. Reopen with a new document. You can run TryMe from that document even though the code is not in any code module of that particular document.

This also words from any other .dot file. Code in the ThisDocument module is available, by name, from any document created by that template.

ThisDocument actual referred to the template, not the document, so the datasource was loaded into there instead of the document

The datasource can not load into the template itself unless the template file itself is open.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top