Add macro to multiple documents

D

Dazza

I have developed a macro that I want to include in all word documents in a
folder. Does anyone know of a way to apply a single macro to all word
documents in a folder?

Thanks
 
J

Jezebel

Depends on your version of Word. Recent versions make this quite difficult
for security reasons. With earlier versions you can do this through the VBE
object.

But it's a terrible thing to do. Spreading code around the countryside
creates a maintenance nightmare, and there are nearly always better ways:
why not put the code in an add-in or global module? What are you actually
trying to do?
 
D

Dazza

Yes, absolutely hear what you say and agree but all I am trying to do is log
the opening of documents to a central register ( i.e a text file ).

If you know of an easier way then I'm all ears.

Thanks
 
J

Jonathan West

Dazza said:
Yes, absolutely hear what you say and agree but all I am trying to do is
log
the opening of documents to a central register ( i.e a text file ).

If you know of an easier way then I'm all ears.


Create an add-in. Use the application events to detect when any document is
opened. This article shows you how

Writing application event procedures
http://www.word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm

The add-in is stored in the user startup folder.

Your event procedure can then write the log if the file meets the
appropriate criteria, however you choose to define them.
 
J

Jezebel

If it's on your own machine, put an AutoOpen macro in normal.dot. That will
run when any document is opened. If it's for general use, create an add-in
as Jonathan suggests.
 

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