I would like a macro I have created in a template (.dot) to be available in
documents (.doc) created from the template (ie. when other people in my
workplace double-click on the template. At the moment, when I double-click
on the template (it creates a .doc version of it )and I go to the list of
macros, the macro I created doesn't show up in the .doc version. What am I
doing wrong. Thank you for any assistance you can offer.

Re: Macro to be available in documents based on a template by Helmut

Helmut
Fri Oct 19 05:03:56 PDT 2007

Hi,

macros in templates are not transferred
or copied to the doc created from the template.

If you want to have all the macros from a project
of the template in the doc, you'd use something like:


Application.OrganizerCopy Source:="C:\Edit2003\Normal.dot", _
Destination:= "C:\Test\Word\fox-01.doc", _
Name:="UserForm1", _
Object:= wdOrganizerObjectProjectItems

If it is only about one single macro,
things get complicated.

Explore:
Microsoft Visual Basic for Applications Extensibility 5.3

You version may vary from mine.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"





Re: Macro to be available in documents based on a template by mgirving

mgirving
Fri Oct 19 05:21:01 PDT 2007

Thank you Helmut.

I am interested in the suggestion you kindly offered (below). Where do I
insert that text? Thank you again.

If you want to have all the macros from a project
of the template in the doc, you'd use something like:
Application.OrganizerCopy Source:="C:\Edit2003\Normal.dot", _
Destination:= "C:\Test\Word\fox-01.doc", _
Name:="UserForm1", _
Object:= wdOrganizerObjectProjectItems


Re: Macro to be available in documents based on a template by Helmut

Helmut
Fri Oct 19 06:59:29 PDT 2007

Hi,

there is something wrong with destination.
Can't get it to work.

I get "Command failed" whatever I do.

I'm so sorry.

Start a new thread like "OrganizerCopy destination".

Maybe somebody else knows better than me.

:-(

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"



Re: Macro to be available in documents based on a template by Jonathan

Jonathan
Fri Oct 19 07:10:40 PDT 2007


"Helmut Weber" <nbhymsjxdgcn@mailinator.com> wrote in message
news:godhh3pm0hqrlvib0l95dkk21l37lrdldh@4ax.com...
> Hi,
>
> there is something wrong with destination.
> Can't get it to work.
>
> I get "Command failed" whatever I do.
>
> I'm so sorry.
>
> Start a new thread like "OrganizerCopy destination".
>
> Maybe somebody else knows better than me.
>

If I recall, a failure will occur if either of the following conditions is
true

1. An item of that name already exists in the destination

2. Either the source or destination contains a VBA project that has been
protected against viewing.

There may be other reasons as well, but those are the two I remember off the
top of my head.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: Macro to be available in documents based on a template by Helmut

Helmut
Fri Oct 19 15:53:58 PDT 2007

Hi Jonathan,

very weird, indeed.

I can record a macro without problems.

Sub Macro6()
Application.OrganizerCopy Source:="C:\Edit2003\Normal.dot",
Destination:= _
"C:\Test\Word\organizer.doc", Name:="UserForm1", Object:= _
wdOrganizerObjectProjectItems
End Sub

The userform was copied.
I remove userform1 from organizer.doc.
I can record the same macro again without problems.

Yet, when trying to run the macro,
I get "Command failed".
Doesn't matter whether I try it on the same document,
having removed userform1,
or on a new blank document.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


Re: Macro to be available in documents based on a template by Russ

Russ
Sat Oct 20 00:29:57 PDT 2007

Helmut and Jonathan,
Apparently Microsoft broke the code for automation for copying between
certain sources and destinations, to avoid spreading macro viruses. They
allow you to manually do what the recorded macro recorded. But then not
allow it to run under automation.

+++++++Quote
This method has one notable limitation: you cannot copy project items from
the Normal template to any other file. This is by design, to prevent the
spread of macro viruses.

In addition, you cannot copy projects to or from a template that is loaded
as an add-in or reference, unless the template is open in Word for editing.
++++++++UnQuote

<http://support.microsoft.com/kb/211466/EN-US/>
+++++++Quote
Application.OrganizerCopy
Source Target Valid Err Error Message
------------------------------------------------------------------------
Document Document Yes
Document Template Yes
Document Normal Yes
Document Global Temp No* 5940 The project item cannot be copied
Template Document Yes
Template Template Yes
Template Normal Yes
Template Global Temp No* 5940 The project item cannot be copied
Normal Document No 4198 Command failed
Normal Template No 4198 Command failed
Normal Normal No 4198 Command failed
Normal Global Temp No 4198 Command failed
Global Temp Document No 4198 Command failed
Global Temp Template No 4198 Command failed
Global Temp Normal No 4198 Command failed
Global Temp Global Temp No 5940 The project item cannot be copied

NOTE: You can copy from a document or template to a global template if the
global template is open in Word for editing.
++++++++UnQuote



> Hi Jonathan,
>
> very weird, indeed.
>
> I can record a macro without problems.
>
> Sub Macro6()
> Application.OrganizerCopy Source:="C:\Edit2003\Normal.dot",
> Destination:= _
> "C:\Test\Word\organizer.doc", Name:="UserForm1", Object:= _
> wdOrganizerObjectProjectItems
> End Sub
>
> The userform was copied.
> I remove userform1 from organizer.doc.
> I can record the same macro again without problems.
>
> Yet, when trying to run the macro,
> I get "Command failed".
> Doesn't matter whether I try it on the same document,
> having removed userform1,
> or on a new blank document.

--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID


Re: Macro to be available in documents based on a template by Helmut

Helmut
Sat Oct 20 03:32:35 PDT 2007

Hi Russ,

thx for the information.

Though not even organizercopy
from one document to another is working.

Application.OrganizerCopy _
Source:="C:\Test\Word\MyNormal.doc", _
Destination:="C:\Test\Word\Import.doc", _
Name:="UserForm1", _
Object:=wdOrganizerObjectProjectItems

No way.

If it has to be, my advice to the OP would be,
to put the macro in a doc, open that doc
and save it under another name,
or make a copy of the doc with the macro,
and open that copy.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"



Re: Macro to be available in documents based on a template by Russ

Russ
Sun Oct 21 02:13:42 PDT 2007

Another workaround as suggested in the link I gave with the previous
information:
=======Quote
To work around this behavior, use the VBComponent Export method to save your
module or form as a BAS or FRM file, and then use the VBComponent.Import
method to import the file into the project that you want.

For example, use the following sample code:
Sub ExportImportModule()
'Export Module1 from Normal to a BAS file
VBE.VBProjects("Normal").VBComponents("Module1").Export _
FileName:="C:\My Documents\Module1.bas"
'Import this BAS file into the desired file
VBE.VBProjects("DocProj").VBComponents.Import _
FileName:="C:\My Documents\Module1.bas"
End Sub
=========UnQuote
I think this code requires a reference to VBA extensions or extensibility
enabled in the VBA Editor menu Tools/References... Dialog.

> Hi Russ,
>
> thx for the information.
>
> Though not even organizercopy
> from one document to another is working.
>
> Application.OrganizerCopy _
> Source:="C:\Test\Word\MyNormal.doc", _
> Destination:="C:\Test\Word\Import.doc", _
> Name:="UserForm1", _
> Object:=wdOrganizerObjectProjectItems
>
> No way.
>
> If it has to be, my advice to the OP would be,
> to put the macro in a doc, open that doc
> and save it under another name,
> or make a copy of the doc with the macro,
> and open that copy.

--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID