Template modules not inherited by new document

S

sconlon

In a custom Word template I have some code that I want to use in each
new document created using the template. However, it seems that a
newly created document does not inherit the module from the template.
I have previously done this in Excel, i.e. had code in an XLT template
that was inherited in each new workbook.

Is there any way of getting the template code into the new document?

Thanks,
Seamus
 
J

Jonathan West

sconlon said:
In a custom Word template I have some code that I want to use in each
new document created using the template. However, it seems that a
newly created document does not inherit the module from the template.
I have previously done this in Excel, i.e. had code in an XLT template
that was inherited in each new workbook.

Is there any way of getting the template code into the new document?

You can use the OrganiserCopy method, but i would recommend against. Word
works differently from Excel. In Excel, each workbook is entirely
self-contained, and a new workbook includes the code of the template.

In Word, the code (along with various other items, such as Autotext entries)
is *not* copied across. Instead, the document maintains a reference to the
template it was based on, and the template's code is available.

if you include code in a Word document and send it on to somebody else, the
chances are that the code will be prevented from running by the user's
security settings.
 
S

Stefan Blom

Note that the code in a template will be accessible to any document created
from that template (or associated with that template via the Templates and
Add-Ins dialog box), so there is no need to copy the code to the document.
 
S

sconlon

Ok, the thing is that the template is used within Goldmine to create
the new document and in this case I notice that the new document
VBAproject does not include a reference to the templateproject as it
does when you create the new document within Word. So it would seem
that there is no way to get at the template code etc from within the
new document.

I thought about using an AutoNew macro in the template to copy the
code, forms and modules to the new document and it appears that
AutoNew does run ok but it seems like such a complicated way of doing
it. Think I'll use Excel instead.

Seamus
 
J

Jonathan West

sconlon said:
Ok, the thing is that the template is used within Goldmine to create
the new document and in this case I notice that the new document
VBAproject does not include a reference to the templateproject as it
does when you create the new document within Word. So it would seem
that there is no way to get at the template code etc from within the
new document.

Set the AttachedTemplate property of the document to point to where the
template is.
I thought about using an AutoNew macro in the template to copy the
code, forms and modules to the new document and it appears that
AutoNew does run ok but it seems like such a complicated way of doing
it. Think I'll use Excel instead.

If that's easier. Alternatively, if you create the code in a template and
move the template into Word's Starup folder, the code will be available
irrespective of which template the document is attached to.
 
S

sconlon

If that's easier. Alternatively, if you create the code in a template and
move the template into Word's Starup folder, the code will be available
irrespective of which template the document is attached to.

Many thanks for the suggestion but I started on the Excel version and
it's much
easier and in fact is better suited to the job.

Thanks again for the help.

Seamus
 

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