Copy Macro using Word Basic

M

Mark J

I want to copy a macro between two Word templates using Word Basic commands.
I am using Word 2003 and I think I need to use the Organizer Copy method but
I can't work out what type I should be using. The examples in the help are
for AutoTextEntry and Style. I thought I should use Module or Macro but
neither of these appear in the type list when I try to "Dim variable as"
M
 
J

Jonathan West

Mark J said:
I want to copy a macro between two Word templates using Word Basic
commands.
I am using Word 2003 and I think I need to use the Organizer Copy method
but
I can't work out what type I should be using. The examples in the help are
for AutoTextEntry and Style. I thought I should use Module or Macro but
neither of these appear in the type list when I try to "Dim variable as"
M

Using the OrganzerCopy method, you cannot copy an individual macro, only a
whole module of code. Of course, if your macro and any other routines it
calls are in a self-contained module, then you can use the OrganizerCopy
method to copy the module. To copy a module, you need to set the Object
parameter to wdOrganizerObjectProjectItems, and the Name parameter to the
name of the module you are copying.
 
M

Mark J

Jonathan West said:
Using the OrganzerCopy method, you cannot copy an individual macro, only a
whole module of code. Of course, if your macro and any other routines it
calls are in a self-contained module, then you can use the OrganizerCopy
method to copy the module. To copy a module, you need to set the Object
parameter to wdOrganizerObjectProjectItems, and the Name parameter to the
name of the module you are copying.

Hi Jonathan,
Unfortunately - this didn't work :-(
If I try and run the following (just to see if I can find the Module I want
to copy):

Dim mn As WdOrganizerObject

For Each mn In ActiveDocument
x = 5
Next mn

I get an error message: "For Each control variable must be Variant or Object".

You will also see that I had to define mn as a WdOrganizerObject, not as a
wdOrganizerObjectProjectItems as you advised. That type is not in the list
and if I type it manyally I get an unrecognised type error.

Any other suggestions?
 
J

Jonathan West

Mark J said:
Hi Jonathan,
Unfortunately - this didn't work :-(
If I try and run the following (just to see if I can find the Module I
want
to copy):

Dim mn As WdOrganizerObject

For Each mn In ActiveDocument
x = 5
Next mn

I get an error message: "For Each control variable must be Variant or
Object".

You will also see that I had to define mn as a WdOrganizerObject, not as a
wdOrganizerObjectProjectItems as you advised. That type is not in the list
and if I type it manyally I get an unrecognised type error.

Any other suggestions?

Yes. You're not using the OrganizerCopy method correctly. Suppose your
source document is "C:\myfolder\mysource.dot" and your target document is
"C:\myfolder\mytarget.dot", and you was to copy the module myModule from one
to the other, you proceed as follows

Application.OrganizerCopy _
Source:="C:\myfolder\mysource.dot", _
Destination:="C:\myfolder\mytarget.dot", Name:="myModule", _
Object:= wdOrganizerObjectProjectItems
 

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