Modules

T

Tonya Marshall

Questions about modules.

When I looked in Templates & Add Ins - Organizer in the Duplex Printing
template I could see in the macro projects that there were NewMacros and
Module1. I expect that I can copy either NM’s or M1 into another
template, which I will call, “MyTemplate,” for clarity.

I may not want to get rid of the NM’s in MyTemplate so I could just copy
what I wanted otherwise. Could I move the macro in NewMacros in the
Duplex template to, say, Module2 and copy it into the My Template so I
could keep the NewMacros in MyTemplate? Does a template that contains
macros have to have a NewMacros project in it or can it just have
Module1, 2, etc?

I have a template in Word Startup that I’ve named Global.dot and it has
4 toolbars. There are many macros in the template and I would like to
separate them into 4 modules so that the macros corresponding to each
toolbar are in a module by themselves. If I move them into a module will
they continue to work or do I have to make new toolbar buttons for them?

Is it possible to name the modules something other than Module1, 2, etc?
 
H

Helmut Weber

Hi Tonya,
to the best of my knowledge,
you don't need a NewMacros module, not project!
You can have just Module1, 2, etc.
I have a template in Word Startup that I’ve named Global.dot and it has
4 toolbars. There are many macros in the template and I would like to
separate them into 4 modules so that the macros corresponding to each
toolbar are in a module by themselves. If I move them into a module will
they continue to work or do I have to make new toolbar buttons for them?
If you move macros from one module to another, buttons don't find them
anymore. To maintain the old button face, you have to create a new
button, copy the old button face and paste it over the new button
face. Tedious, sure! And delete the old one.
Is it possible to name the modules something other than Module1, 2, etc?
Yes. But the effect is the same as with moving macros. Probably all
that moving and reassigning can be done programmatically.
But though I like programming, I'd rather do it manually.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
T

Tonya Marshall

Thanks so much for the info, Helmut. Looks like my project is cut out
for me if that's what I decide to do. As far as renaming the modules,
that's really not that important to me. I just thoughtt that if it was
simple to do, it would be kind of nice to give each module a descriptive
name.
Tonya Marshall
 
J

Jay Freedman

Hi Tonya,

Just to add a bit to what Helmut said:

- The NewMacros module is created when you use the macro recorder and
don't specify a module name when you name the macro. (Tip: If you
already have another module in the template, say "MyModule", and you
want to record a macro into it, you can type "MyModule.MyNewMacro" in
the recorder dialog.)

- Renaming a module works well if you do the renaming as soon as you
create the module, before you assign any buttons to the macros in it.
After you've created buttons, as Helmut said, the button is tied to
the combination of the module name and the macro name, and there's no
easy way to change it.

- I tend to create a separate module for each macro. The module may
contain one main routine that appears in the Macros list and several
private subs or functions, but the whole thing acts as a single
program. The most common exception to that rule is a single module for
Auto macros (but more often I write event routines).
 
J

Jonathan West

Hi Tonya

Tonya Marshall said:
Questions about modules.

When I looked in Templates & Add Ins - Organizer in the Duplex Printing
template I could see in the macro projects that there were NewMacros and
Module1. I expect that I can copy either NM’s or M1 into another template,
which I will call, “MyTemplate,” for clarity.

I may not want to get rid of the NM’s in MyTemplate so I could just copy
what I wanted otherwise. Could I move the macro in NewMacros in the Duplex
template to, say, Module2 and copy it into the My Template so I could keep
the NewMacros in MyTemplate?
Yes.

Does a template that contains macros have to have a NewMacros project in
it or can it just have Module1, 2, etc?

No. NewMacros is simply the default name given to the module where recorded
macros are placed.
I have a template in Word Startup that I’ve named Global.dot and it has 4
toolbars. There are many macros in the template and I would like to
separate them into 4 modules so that the macros corresponding to each
toolbar are in a module by themselves. If I move them into a module will
they continue to work or do I have to make new toolbar buttons for them?

If you change either the macro name or the module name, then you will need
to rebuild the toolbar buttons, because the button calls the macro on the
basis of both names.
Is it possible to name the modules something other than Module1, 2, etc?

Yes. In the VBA editor, open the module. You can change the name of the
module by changing the (Name) property in the property pane in the bottom
left of the window.

By the way, you can also change the name of the project itself to something
shorter than TemplateProject. This can be useful because having a short
project name and a short module name gives you a change of actually being
able to see the routine name in the Tools Customize dialog, when you are
assigning routines to toolbar buttons or keyboard shortcuts. With the VBA
editor open, go to Tools, TemplateProject Properties, and change the name in
the Properties dialog that appears.


On a more general note, there are the following good reasons to divide a
project into modules.

1. Its easier to organise things, and you are more easily able to copy
macros from one template to another if they relates macros are grouped
together in a single module.

2. Routines, Declare statements and global variables that are declared using
the Private keyword can only be accessed by other routines *in the same
module*. Declaring everything as private unless you definitely intend it to
be called from another module is a good way of ensuring that adding a module
to another template isn't going to mess up the existing code there because
of a name clash between two routines of the same name in different modules.
 
T

Tonya Marshall

Thank you all for your suggestions and help. I see I have my work cut
out for me and it will be very nice to organize my macros into some
semblance of order. I ran a find & replace request for () and replacing
with () to count the macros in Global.dot - 54 macros! All dumped into
NewMacros. Some of the macros have been in there since WD97 and have
been carried into WD '00, '02, and now '03. I just pulled the buttons
off the toolbars if I didn't use them anymore such as macros that have
been replaced by the Places bar in the File/Open dialog. It's going to b
kind of like cleaning out an attic <g>.

I copied all of the macros in Global.dot and pasted them into a document
then separated them into 5 "modulename" documents in a new folder in My
Documents. I will make new toolbars with different names than the ones
in Global.dot so I can have the ones in Global.dot open and be able to
copy and paste some of the button images to the toolbars in
NewGlobal.dot or whatever I plan to call it.

As you said, Jonathan, it will be much easier to find the macros in the
Customize dialog (and why in the dickens don't they make that window
bigger?) with a different project name.

I have 4 other templates in Word Startup that I will put the macros into
the new template and will end up with only one template with a few more
modules in it.

Doubtless, I will be back with more questions. This is going to take me
a bit of time to do.

Thank you, again.

Tonya Marshall

<snip>
 
T

Tonya Marshall

It went easier and faster than I thought it would. Finding the macros in
Customize/Commands was so much faster and easier with a different
Template Project name and with different module names. I named the
toolbars the same names but put "Bar" after the names so I could have
both toolbars open and copy & paste the button images from the old to
the new and not get them mixed up. Then after I moved the old templates
out of Startup and put in the new one I renamed the toolbars with the
old names and changed the macros that open and close them back to the
old names.

I have 1 template in Word Startup instead of 5. It's certainly much
easier to keep track of the macros. Everything seems to be working
right, but I saved the old startup templates in a folder ... just in case.

Thanks again for all your help.

Tonya Marshall
 
T

Tonya Marshall

lol ... you've created a monster. Now I've cleaned up my Normal.dot (it
doesn't have very many macros in it) and put the macros in separate modules.
Tonya Marshall

<snip>
 
J

Jean-Guy Marcil

Tonya Marshall was telling us:
Tonya Marshall nous racontait que :
lol ... you've created a monster. Now I've cleaned up my Normal.dot
(it doesn't have very many macros in it) and put the macros in
separate modules. Tonya Marshall

In a global template other than Normal.dot, I hope?
Or, at least, if you want to hang on to those macros, make sure you have a
backup of your Normal.dot.

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

Tonya Marshall

I have XNormal.dot, the one that has the macros in it but not separated
into modules. I think there are only 5 in it. My Global.dot in Startup
has the majority of macros in it.
Tonya Marshall
 
T

Tonya Marshall

Well, I found out the folly of doing that. Normal.dot needs only
NewMacros or the macros get put into every new template. :/
Tonya Marshall
 
J

Jean-Guy Marcil

Tonya Marshall was telling us:
Tonya Marshall nous racontait que :
Well, I found out the folly of doing that. Normal.dot needs only
NewMacros or the macros get put into every new template. :/
Tonya Marshall

????
What do you mean?

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

Tonya Marshall

When I made a new template and put a macro in it, every macro that was
in Normal.dot was in the new template, too. I went back to the old
Normal.dot and that doesn't happen. If you want I can send you an
example of what happened.
Tonya Marshall
 
J

Jean-Guy Marcil

Tonya Marshall was telling us:
Tonya Marshall nous racontait que :
When I made a new template and put a macro in it, every macro that was
in Normal.dot was in the new template, too. I went back to the old
Normal.dot and that doesn't happen. If you want I can send you an
example of what happened.

Never seen that before!
I do not think it has anything to do with the module name.
You must have done something while you weren't looking!

I have had tons of modules/macros in my Normal.dot over the years, and never
have they been transferred to a newly created template.
Unless you had Normal.dot still open and you did "Save as" to create a
template, I do not see how it would happen.

Yet another Normal.dot mystery! See why it is better to leave it alone! I
never save anything important in Normal.dot, just macro scraps I want to
quickly test. As soon as I get serious with wanting to preserve my work, I
create a template or a document, depending on my purpose.
If I want the said macros to be available at all times, I dump them in a
template that is located in my Start-up folder.

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

Tonya Marshall

I have only a few macros in N.dot. One is a public sub and I think it
has to be there, plus one that has commands to keep the reviewing
toolbar and the web toolbar from popping up itheir ugly heads and a
close macro that prevents the bug that doesn't save changes to a
template done through a document generated from the template. I
discovered this when I wanted to change a template style through a
document from the template and I was not prompted to save the changes to
the template.
The glitch was tested by Beth Melton and she declared it an official
but. Closing the window rather than using File/Close would bring a
prompt, though, and the macro reflects that by closing the doc window.
Tonya Marshall
 

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