From: avkokin on
There is one template. By this template I'm creating new document. I
need to copy one macro from this template into this document into
module ThisDocument. How?
Thank you.
From: Fumei2 via OfficeKB.com on
Just one macro? There are others that you do NOT want copied over? You do
know, I assume, that procedures in a template can be used in a document
cloned from that template - as long as the .DOT file is available.

To answer your question though, you could put that procedure into a exported
file (as a separate module perhaps), and then as part of your template
Document_New(), import that file into the newly cloned document VBA project.

So say you put your macro into a module - Yadda. Export it as Yadda.bas
(right click the module to export it). Now write the following into the
Document_New event of the template.

Private Sub Document_New()
ActiveDocument.VBProject.VBComponents.Import "c:\zzz\Yadda.bas"

End Sub

with of course the appropriate path to the file. Now the DOCUMENT, cloned
from the template, will have the imported code module.

Note that you can import any module you like, it does not have to be from the
template cloning itself. So you could, if you like, export some module from
a different template, and import it into a document. Whatever.

Gerry


avkokin wrote:
>There is one template. By this template I'm creating new document. I
>need to copy one macro from this template into this document into
>module ThisDocument. How?
>Thank you.

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1

From: Fumei2 via OfficeKB.com on
Oops. I missed the part about getting it into ThisDocument. Do yo uhave to
have it in ThisDocument? If so, then the only way is to actually write, line-
by-line, a procedure into ThisDocument.

Fumei2 wrote:
>Just one macro? There are others that you do NOT want copied over? You do
>know, I assume, that procedures in a template can be used in a document
>cloned from that template - as long as the .DOT file is available.
>
>To answer your question though, you could put that procedure into a exported
>file (as a separate module perhaps), and then as part of your template
>Document_New(), import that file into the newly cloned document VBA project.
>
>So say you put your macro into a module - Yadda. Export it as Yadda.bas
>(right click the module to export it). Now write the following into the
>Document_New event of the template.
>
>Private Sub Document_New()
>ActiveDocument.VBProject.VBComponents.Import "c:\zzz\Yadda.bas"
>
>End Sub
>
>with of course the appropriate path to the file. Now the DOCUMENT, cloned
>from the template, will have the imported code module.
>
>Note that you can import any module you like, it does not have to be from the
>template cloning itself. So you could, if you like, export some module from
>a different template, and import it into a document. Whatever.
>
>Gerry
>
>>There is one template. By this template I'm creating new document. I
>>need to copy one macro from this template into this document into
>>module ThisDocument. How?
>>Thank you.
>

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1