How to refer to template code from doc?

Z

zSplash

Within my template (a workgroup template: "Workgroup.dot"), I have a module
named "Module1" with a sub called "MySub". From the code within the working
document ("MyDoc"), I get an error at the following code:
ActiveDocument.FormFields(4).ExitMacro = "MySub"

The error is: Run-time error '4120', bad parameter.

I have tried: ActiveDocument.Formfields(4).ExitMacro = "Module1.MySub" and
made sure there was reference to the workgroup template, but still get the
same error.

Help!??

TIA
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Within my template (a workgroup template: "Workgroup.dot"), I have a
module named "Module1" with a sub called "MySub". From the code
within the working document ("MyDoc"), I get an error at the
following code: ActiveDocument.FormFields(4).ExitMacro =
"MySub"

The error is: Run-time error '4120', bad parameter.

I have tried: ActiveDocument.Formfields(4).ExitMacro =
"Module1.MySub" and made sure there was reference to the workgroup
template, but still get the same error.


Have you tried with the project name prefixing the module name, as in:

ActiveDocument.Formfields(4).ExitMacro ="MyProject.Module1.MySub"

Also, make sure your target sub is not Private.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Within my template (a workgroup template: "Workgroup.dot"), I have a

Sorry, I just clicked to that detail...
How did you set the reference to a Workgroup template?

Normally, workgroup templates are not loaded when Word starts as templates
in the Startup folder are.

So, unless you have created/opened a document currently based on the
workgroup template, or did something to load the tempalte, its sub will not
be available.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
Z

zSplash

Thanks for helping, Jean-Guy.

I am now trying it as an attached template (so I can "see" the code in
theVBA editor). The project name in the VBA editor is
"Normal(Workgroup)" -- does that mean the project name is Normal, or
Workgroup? So, I have tried:
ActiveDocument.FormFields(4).ExitMacro = "MySub"
ActiveDocument.FormFields(4).ExitMacro = "Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro = "Workgroup.Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro =
"Normal(Workgroup).Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro =
"Normal.Workgroup.Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro = "Workgroup!Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro =
"Workgroup!Workgroup.Module1.MySub"

Sometimes I get error '5941" - the requested member of the collection
doesn't exist; and sometimes error '4120' - bad parameter.

When I stop the code, and manually go to FormField(4) and see what macros I
can run on exit, I "see" MySub. I can set it manually, but not through
code. I think I'm not referencing it correctly, but I can do it just fine
manually. (uffta.)

st.
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Thanks for helping, Jean-Guy.

I am now trying it as an attached template (so I can "see" the code in
theVBA editor). The project name in the VBA editor is
"Normal(Workgroup)" -- does that mean the project name is Normal, or
Workgroup? So, I have tried:
ActiveDocument.FormFields(4).ExitMacro = "MySub"
ActiveDocument.FormFields(4).ExitMacro = "Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro = "Workgroup.Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro =
"Normal(Workgroup).Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro =
"Normal.Workgroup.Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro = "Workgroup!Module1.MySub"
ActiveDocument.FormFields(4).ExitMacro =
"Workgroup!Workgroup.Module1.MySub"

Sometimes I get error '5941" - the requested member of the collection
doesn't exist; and sometimes error '4120' - bad parameter.

When I stop the code, and manually go to FormField(4) and see what
macros I can run on exit, I "see" MySub. I can set it manually, but
not through code. I think I'm not referencing it correctly, but I
can do it just fine manually. (uffta.)

"Normal" is the name of the project and "Workgroup" is the name of the
container document/template.
So, you should have:

ActiveDocument.FormFields(4).ExitMacro = "Normal.Module1.MySub"

The only one you haven't tried ;-)

Sometimes, to avoid confusion and if the name is short, I name the project
the same as the template...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
Z

zSplash

Hej, Jean-Guy. What you suggested worked fine in one instance, but still
errors in my ExitMacro code. I have re-posted the question, but appreciate
any hope (freudian, I guess) -- help -- you can provide.

st.
 

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