macro from Word template vanish in New doc ?!?

S

sagaz

Hi

I've build a word (V97) template (dot file) with macros triggered by the "Document_new" event

I need the documents based on this template run this macro. But on doc creation, no macro from the new doc run. In fact, the template's macro are not copied to document. So, only macro from attached template run

Did I miss something ? How to copy the macros too from the template to the new doc and how to Execute it automatically

Thanks for answer..
 
J

Jonathan West

Hi sagaz

sagaz said:
Hi,

I've build a word (V97) template (dot file) with macros triggered by the "Document_new" event.

I need the documents based on this template run this macro. But on doc
creation, no macro from the new doc run. In fact, the template's macro are
not copied to document. So, only macro from attached template run.


This is normal behaviour for Word.
Did I miss something ?
No.

How to copy the macros too from the template to the new doc and how to
Execute it automatically?

I would strongly recommend you don't try to do this, you will fall foul of
the ecurity settings on most customer machines and your macros won't run
even if they are included in the document.

Forget for a moment about what macros go where, and describe in general
terms what you are trying to achieve overall. It may be that a different
approach will be better.
 
S

Sagaz

Oups, I thought templates work in Word like in Excel

The final (and very usual) goal is to generate a document from a template (for litteral datas) and compute some more specific datas from environnement parameters (like date, counter etc ...) depending on environnement parameters

Perhaps, I can try to use template's Open event (which is ever called in new document creation) and call the appropriate macro to update the specific datas in the new document. But I need a not ambiguous reference to this one (cause other documents could be open in the same Application)

Regards
 
J

Jonathan West

Hi Sagaz,

If you use VBA to create the document, you can create on object variable
which unambiguously refers to that document, and which you can use to make
changes to the document.

Dim oDoc as Document
Set oDoc = Documents.Add(Template:="C:Templates\My Template.dot")


Then you can uise oDoc to make changes to the document and eventually change
it.

--
Regards
Jonathan West - Word MVP
http://www.multilinker.com
Please reply to the newsgroup


Sagaz said:
Oups, I thought templates work in Word like in Excel !

The final (and very usual) goal is to generate a document from a template
(for litteral datas) and compute some more specific datas from environnement
parameters (like date, counter etc ...) depending on environnement
parameters.
Perhaps, I can try to use template's Open event (which is ever called in
new document creation) and call the appropriate macro to update the specific
datas in the new document. But I need a not ambiguous reference to this one
(cause other documents could be open in the same Application).
 

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