setting ExitMacro (to template)

Z

zSplash

Okay, get a load of this:

I am trying to check code using an attached template, and after I perfect
the code, make the attached template a workgroup template. I hope that's
proper.

So, I name the template "Forms.dot" and make it an attached template. (When
"Forms.dot" is my "Normal.dot", the code works perfectly.)

Now, as an attached template (with a blank Normal.dot), the code errors out
at the following code:

ActiveDocument.FormFields(4).ExitMacro = "doCopies"

"doCopies" is a sub within the attached template "Forms.dot", which is where
the code errors. I shouldn't have to refer to the module or project if it's
in the same routine, should I? When I halt the code, and manually go to the
document, I can manually "see" the sub "doCopies", so it's available, but
still my code errors.

Anyway, I can't get past this. Can anyone offer some help?

TIA
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Okay, get a load of this:

I am trying to check code using an attached template, and after I
perfect the code, make the attached template a workgroup template. I
hope that's proper.

Before going any further, we have to clear up the terminology.

An attached template is the template to which a document is attached, or
based on, or created from. The default attached template is Normal.dot, IOW,
if you create a document without specifying a template, Word will use
Normal.dot as the template, which will become the new document's attached
template. You can programmatically change an attached template on a
document, but this means that the previously attached template is unloaded
from memory and its project/modules/sub are not available anymore.
A workgroup template is just a template that resides in the workgroup
folder. It does not have any special status in the Object model. The status,
if you can call it that, is provided by the fact that Word recognized the
folder from Tools > Options >File Locations tab and will list the templates
from the folder when you do File > New.

If the code resides in a template, then it can always call any other
standard module's sub from within the same project, unless the subs are
private or need parameters and the call does not provide any.

Please explain what you mean by your first paragraph.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
Z

zSplash

Thanks so much, Jean-Guy. Your help is very enlightening!

Here's the deal: I write code, using a clean Normal.dot. Then, I rename
that Normal.dot to Forms.dot. Then, I want to test the code, and since I
can't test it when it's a workgroup template ("Project is unviewable"), I
attach the Forms.dot to MyDoc, the working document. That way, from the VBA
editor, I can actually see what's happening with the code. Maybe that's a
gruesome way to do it, but that's what I do.

So, in this case, I have the code working perfectly in Normal.dot. Then, I
rename it to Forms.dot, and attach it to MyDoc. (When I did that, I saw a
new Normal project in the editor, so I assumed a new one is created, even
though the document is attached to Forms.dot -- wrong assumption, I guess,
as per your explanation re: attachment.) Now, when I run the code, I get
errors leading me to believe the references to the attached template's subs
are not valid.

So, waiting for help, I commented out the exitMacro problem, and moved on.
Now, I have unattached the Forms.dot as an attached template, put Forms.dot
in the Template Workgroup folder, and am trying to run the code as a
workgroup template. Yet another error is appearing: '424' object required.
This appears when I try to run SubName at the following line:
ProjectName.ModuleName.SubName

So, that's the rest of the story. Any help you can provide is awesome.
Thanks again.

st.
 
Z

zSplash

Okay, Jean-Guy. The SubName problem was resolved by referencing the
Form.dot in the reference library.

What do you think about my process of "making" templates' code? Too
convoluted for words?

st.
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Thanks so much, Jean-Guy. Your help is very enlightening!

Here's the deal: I write code, using a clean Normal.dot. Then, I
rename that Normal.dot to Forms.dot. Then, I want to test the code,
and since I can't test it when it's a workgroup template ("Project is

Again, what is a Workgroup template to you? I do not think you are using the
right word. I think you mean a global template. Where is it stored? See my
reply to your other post in this thread.
unviewable"), I attach the Forms.dot to MyDoc, the working document.
That way, from the VBA editor, I can actually see what's happening
with the code. Maybe that's a gruesome way to do it, but that's what
I do.

So, in this case, I have the code working perfectly in Normal.dot.
Then, I rename it to Forms.dot, and attach it to MyDoc. (When I did
that, I saw a new Normal project in the editor, so I assumed a new
one is created, even though the document is attached to Forms.dot --
wrong assumption, I guess, as per your explanation re: attachment.)
Now, when I run the code, I get errors leading me to believe the
references to the attached template's subs are not valid.

So, waiting for help, I commented out the exitMacro problem, and
moved on. Now, I have unattached the Forms.dot as an attached
template, put Forms.dot in the Template Workgroup folder, and am
trying to run the code as a workgroup template. Yet another error is
appearing: '424' object required. This appears when I try to run
SubName at the following line:
ProjectName.ModuleName.SubName

So, that's the rest of the story. Any help you can provide is
awesome. Thanks again.

st.

--
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 :
Okay, Jean-Guy. The SubName problem was resolved by referencing the
Form.dot in the reference library.

What do you think about my process of "making" templates' code? Too
convoluted for words?

To say the least!

The key question is:
How will the code be used?
2 possible answers:
1) Only from documents created from a specific template.
2) All documents, regardless of the attached templates.

In both cases you need a template. But,
With 1), only documents created from the said template should have access to
the code. So, if you do not already have the template, you create a document
from Normal.dot, and then do "Save As" and choose template as document type.
From that point on, you open the template directly (right click in explorer
to Open) to work on the code, or , depending on the nature of the code, you
create a document from the template and test/adjust the code from the
document. In the VBA editor, if you click on Save, you are actually saving
the template and the code, not the document. This way you do not need to
attach/detach template to a document created form Normal.dot to test/adjust
the code.

With 2) you follow the same principles, but since no documents will be
created from the template, you have to store the template in the Start-up
folder. When you do that, the template loads when Word starts and its
code/autotext/toolbars will be available to all documents. Testing the code
in such a template can be a bit trickier. Either you open the template
directly or create a document from it, because even though it loads with
Word, you cannot directly access the code unless it is explicitly open or
used to create documents. But remember that templates in the Startup folder
(Called Global template or Add-ins) are not designed to be used to create
documents from. Finally, in this case, if you have code in other templates
that need to refer to the code in the global template, then those templates
need to set a reference to the global template in Tools > References in the
VBA editor window.

Finally, as I wrote before, a Workgroup template is simply a template in
the Workgroup folder and has no special status. It is similar to user
templates that are stored in the user folder. See the "File Locations" tab
in Options.

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

zSplash

Thanks for your help, Jean-Guy.
I'm sorry I'm not being technically correct, Jean-Guy. You are completely
right. Forms.dot is just a template that resides in the workgroup folder.
It has no special status, other than its residence.

So, back to the question: How can I refer to MySub, which is in MyModule,
within MyProject, which is really in a document called Forms.dot so that I
can "set" the exitMacro?
ActiveDocument.FormFields(4).ExitMacro = "MySub"
None of the previously listed attempts work, though if I stop the code and
just go to MyDoc, I can manually assign the exitMacro to be "MySub".

st.
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Thanks for your help, Jean-Guy.
I'm sorry I'm not being technically correct, Jean-Guy. You are
completely right. Forms.dot is just a template that resides in the
workgroup folder. It has no special status, other than its residence.

So, back to the question: How can I refer to MySub, which is in
MyModule, within MyProject, which is really in a document called
Forms.dot so that I can "set" the exitMacro?
ActiveDocument.FormFields(4).ExitMacro = "MySub"
None of the previously listed attempts work, though if I stop the
code and just go to MyDoc, I can manually assign the exitMacro to be
"MySub".

And back to my question! ;-)

The key question is:
How will the code be used?
2 possible answers:
1) Only from documents created from a specific template.
2) All documents, regardless of the attached templates.

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

zSplash

In the long run, the code will be used for (2) all documents, regardless of
the attached templates.
(Because, in the long run, the code will be in an unattached template.)
(whew!)

st.
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
In the long run, the code will be used for (2) all documents,
regardless of the attached templates.
(Because, in the long run, the code will be in an unattached
template.) (whew!)

st.

From the look of your code (Activating a macro from an Exit event in a form
field in a protected document) this should work.

Make sure that the template containing the code to be activated from the
Exit event is in the Startup folder. Restart word and run the code to
associate the macro with the form's field's Exit event.
It should work if you make sure to mention the whole path
(Project.Module.Sub) and that the sub is public.
It does work on my machine.

So if it is not working, you are doing something wrong, or doing something
else that causes problems.

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

zSplash

Oh, THANK YOU so much, Jean-Guy. I really appreciate all your loyal help.

What you suggest seems to work great. Thanks for sticking with me.

st.
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Oh, THANK YOU so much, Jean-Guy. I really appreciate all your loyal
help.

lol
Can I have a cookie now?
What you suggest seems to work great. Thanks for sticking with me.

No problems!

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

zSplash

Oh, my. The exitMacro still won't "set".
I have:
1. pointed the startup folder to the same folder as where the template
is
Make sure that the template containing the code to be activated from the
Exit event is in the Startup folder.
2. Restarted Word and tried to "associate the macro with the form
field's Exit Event
Restart word and run the code to
associate the macro with the form's field's Exit event.
3. Mentioned the whole path in the code:
ActiveDocument.FormFields(4).ExitMacro = "Project.Module.MySub"
It should work if you make sure to mention the whole path
(Project.Module.Sub)
4. The sub (all subs) is public
and that the sub is public.

So, despite all our efforts, we are back to the initial bad parameter error,
4120:
When I halt the code, and manually go to the document, I can
manually "see" the sub "MySub", so it's available. If I manually assign the
exitMacro, the code progresses great. It just doesn't recognize the
"Project.Module.MySub" when assigning the property to the formfield.

Uffta. Any ideas?
 
J

Jean-Guy Marcil

zSplash was telling us:
zSplash nous racontait que :
Oh, my. The exitMacro still won't "set".
I have:
1. pointed the startup folder to the same folder as where the
template is
2. Restarted Word and tried to "associate the macro with the form
field's Exit Event
3. Mentioned the whole path in the code:
ActiveDocument.FormFields(4).ExitMacro =
"Project.Module.MySub"
4. The sub (all subs) is public

So, despite all our efforts, we are back to the initial bad parameter
error, 4120:
When I halt the code, and manually go to the document, I can
manually "see" the sub "MySub", so it's available. If I manually
assign the exitMacro, the code progresses great. It just doesn't
recognize the "Project.Module.MySub" when assigning the property to
the formfield.

Uffta. Any ideas?

No.
It works for me.

If you want, send me the documents and when I have 5 minutes I'll look at
them and report back here in the groups.
Make sure to include a complete procedure describing the steps you used
(Point 2. above needs to be more detailed: Did you run the code on the
template? On a document from the template? On some other document? Did you
save, close and re-open? Have you tried with other macros? etc.)

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

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