modular macros

K

kill_beast

I tried creating a word document with macros, and reference it in other
documents so that all of my code is in one place.

However, I can't get the other documents to save the reference.

Is there a better way to do this? Create a library or something?

Basically, I'm going to have 50+ Word documents, and I'd like the macro to
be in one spot instead of saved seperately wtih each document. That way if I
have to change the code, I won't have to update it everytime.

Any ideas?
 
J

Jay Freedman

I tried creating a word document with macros, and reference it in other
documents so that all of my code is in one place.

However, I can't get the other documents to save the reference.

Is there a better way to do this? Create a library or something?

Basically, I'm going to have 50+ Word documents, and I'd like the macro to
be in one spot instead of saved seperately wtih each document. That way if I
have to change the code, I won't have to update it everytime.

Any ideas?

Macros should never (except in unusual circumstances) be stored in documents.
They should be in templates. This has less to do with updating changed code, and
more to do with the way Word handles macros and macro security. Essentially,
macros stored in documents are always treated as potential viruses.

Macros that are stored in a template (in the Templates folder) used to base new
documents are available in all documents based on that document.

Macros that are stored in a template located in Word's Startup folder are
available in all documents.

See http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm and
http://www.word.mvps.org/FAQs/Customization/WhatTemplatesStore.htm for
background.
 
T

Tony Jollans

I don't really know why but it doesn't seem sufficient just to add a
reference to another document (or template), you must make use of it for it
to 'stick'.
 
K

kill_beast

Well, the confusing thing is that the 50+ documents are all going to be
templates from which other documents will follow.

I hoped that these documents (templates) could access their macro code from
1 location, since it's all going to be the same thing. Namely because I'm
going to have to update this code at a later time int he future, and updating
code for 50+ documents seems like a colossal waste of time if it's all the
same.

Any ideas?
 
J

Jay Freedman

As I already said, "Macros that are stored in a template located in Word's
Startup folder are available in all documents." This is equivalent to the
"macro library" you initially asked about. Put all your common macros into
one template, and store that template in the Startup folder (which by
default is the hidden folder %appdata%\Microsoft\Word\Startup).

The other 50+ documents, if they really are documents (*.doc files), should
not contain any macro code. If they are in fact templates (*.dot files) used
to base new documents through the File > New command or the VBA
Documents.Add method, then some of them might be allowed to contain a few
macros that are specifically required only by the documents based on them.

I hope you did -- or will -- read and understand the articles I pointed to
in my previous post. They explain the concepts that determine where you put
macros.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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