0
votes

I already have .docm files that have simple formatting macros embedded in them. The macros work. However I have 100+ different .docm files that use basically the same macro. Instead of changing the macros on all 100+ .docm files when I need to change a format, I would like to place the macro in a separate text file in a stable location on a network drive and have the macro code in each .docm file reference that text file.

I tried a Call Shell(AppName,1) statement where the AppName contains the path of the txt file, but the compiler won't work with a colon.

I researched creating a macro to change other macros embedded within each document, but was advised against it due to virus scanners.

1
Yes, id advise against code writing code, you could use and AddIn and have the code in the addin, then the macro's call the addin code, so in each of your 100+ you'd have ADDINFUNCTION(), but in the Addin you'd have the code for ADDINFUNCTION(). Google AddIns to Share VBA code in Word or even just AddIns Word VBA. Hope this helps. - Nathan_Sav

1 Answers

0
votes

It's not possible to run a macro from a text file, the way you imagine. (Cool idea, but a security risk, I think.)

Better would be to bring all the macros together in a single template (dotm), which you put in your STARTUP folder. When Word loads, it will load this template (with all its Ribbon customizations and macros) as an "add-in". (See also the Developer/Add-ins dialog box, which is where these can be managed.)

In this way, your code can be managed centrally - but you do have to explicitly open the template in order to make changes to the code. It can't be done just over the loaded add-in (that's only possible with Normal.dotm).

You can also have macros in this add-in template that you call from other macros. This can be done using the Applicaton.Run method.