Code of Template in Doc

  • Thread starter Thread starter Peter Lingo
  • Start date Start date
P

Peter Lingo

Hello,
for a document which is based on a special template it could be sometimes an
advantage, if the code of the template is in the document too.
In this case the document can be distributed without making sure that the
template is correct available on the machines, but the document works fine
nevertheless.

What would be the best way to make sure that the code (including Forms and
code in ThisDocument) of the Template is available in the Document which is
distributed (with selfcreated content). Should I simple make a FileCopy of
the Template to the Document?

Thanks Peter
 
Hi Peter

Before you begin, bear in mind two things.

First, documents can't store AutoTexts. Since many templates with
significant code in them depend on using AutoTexts that are stored in the
template, you may never be able to achieve your aim.

Second, the code won't necessarily work as you expect. The code may have
been written assuming that the code was running from your special template,
and that this template was available. All documents are attached to a
template. If your document is no longer attached to its "old" template with
all the code etc available, then what template will it be attached to?
Normal.dot? If so, any code that is now in the document, and which refers to
the document's template, will be referring to normal.dot. And if that code
relied on the special template, then it may not work. Or, you could leave
the document attached to the "old" template. But on a machine with the "old"
template (or any template with the same name), then you'll have two lots of
code, with potential conflicts and certain maintenance issues.

I guess there are three ways I can think of to get the code etc from
template to document:
1. Manually, using the VBE and the Tools > Templates and Add-ins >
Organizer.

2. Write code that itself copies code from the template to the document.

3. Open the template, File > Save As and save as a document. If necessary,
paste relevant text into that new document.

Just as a check list, you'll have to copy all the following to the document:
- code in modules
- code in classes
- code in ThisDocument events
- userforms and the code behind them
- toolbars
- keyboard shortcuts.

It might be easier to distribute the template<g>.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
Back
Top