h1

Word: Separate out macros and attach them to all documents

October 18, 2009

(Many thanks to Hamish Blunck for helping me with this tip)

I needed to make some macros available to all Word documents I opened (NOT attach them, despite the title of this post). I wouldn’t need the macros for every document, but I would need them for many documents. The documents I was working on used different templates, so adding the macro to each template was not an option. In addition, some of the documents came from organizations where I had no access to, nor control over, their templates. Adding the macro to my Normal.dot template wasn’t an option either — if Normal.dot gets corrupted or deleted, Word will create a new one based on the ‘factory defaults’ — and I would lose all my macros.

What I wanted was a place where I could store all my handy Word macros, and I wanted the macros to be available to all my Word documents, whether I used any of them in a particular document or not.

I also wanted to be able to take my macros wherever I went — having them in a separate file means I can back them up, put them on a USB stick, share them with others, etc.

The ‘quick and dirty’ solution for those who know about these things is to:

  1. Create and save a new blank document as a template (Word 2003: *.dot; Word 2007 and later: *.dotm).
  2. Add your favorite macros and any keyboard assignments to this template. Save and close.
  3. Move your macros template to the Word > STARTUP folder.

For those who require more steps…

Create a new template document for your macros

  1. Create a new document in Word.
  2. Immediately save it with a meaningful name (like macros) as a Document Template file type (Word 2003: macros.dot; Word 2007 and later: macros.dotm).

Don’t close your new template yet — you’re going to add your macros to it next.

Add your macros to your macros template

Macros can come from various places — existing Word documents or templates, the internet, or you can create or record them from scratch.

The critical thing is to locate them then add them to your new macros.dot(m) document.

  1. Open the Macros dialog box (Word 2003: Tools > Macro > Macros; Word 2007: View tab > Macros button).
  2. Type anything in the Macro name field (you’ll be deleting it in a moment, so don’t worry about what it is).
  3. Click Create.
  4. Delete the macro information just created, then paste your favorite macros into the Code window. Each macro should start with a Sub line and end with an End Sub line.
  5. Close the Code window and the Microsoft Visual Basic window to return to your blank document.

Add any keyboard assignments to your macros template (optional)

If you like to run your macros using the keyboard, then now is the time to assign your keyboard combinations to your macros.

  1. Go to Tools > Customize (Word 2003) OR Office button Office_2007_button > Word Options > Customize (Word 2007) OR File > Options (Word 2010 and later).
  2. Click Keyboard (Word 2003) OR Customize (Word 2007 and later; Hint: This button is near the bottom of the window).
  3. On the Customize Keyboard dialog box, select Macros from the Categories list.
  4. Select one of your macros from the list of macros on the right.
  5. Click in the Press new shortcut key field.
  6. Press the keys you want to assign to this function.
  7. Select the template where you want to save this keyboard combination (select your new macros.dot(m) template).
  8. Click Assign.
  9. Click Close to close the Customize Keyboard dialog box.
  10. Close the Customize dialog box (Word 2003) OR the Word Options dialog (Word 2007 and later).
  11. Save and close your macros.dot(m) document.

Move your macros template to your Word STARTUP folder

  1. Copy your macros.dot(m) template document to the clipboard.
  2. Paste it into your Word STARTUP folder; by default, it is located here:
    • Word 2003: C:\Users\<UserName>\Application Data\Microsoft\Word\STARTUP
    • Word 2007 and later: C:\Users\<UserName>\AppData
      \Roaming\Microsoft\Word\STARTUP
  3. You can check your Startup folder location here:
    • Word 2003: Tools > Options > File Locations tab. Select Startup, then click Modify to see the full file path.
    • Word 2007: Office button Office_2007_button > Word Options > Advanced > General section (near the bottom). Click File Locations, then select Startup. Click Modify to see the full file path.
    • Word 2010 and laterFile > Options > Advanced > General section (near the bottom). Click File Locations, then select Startup. Click Modify to see the full file path.

Now whenever you open a Word document or create a new one, the macros in your macros.dot(m) file will be available for you to use.

Very clever. Thanks Hamish!

See also:

[Links last checked January 2013]

16 comments

  1. […] How and where to store this macro so that you can use it with all your Word documents: https://cybertext.wordpress.com/2009/10/18/word-separate-out-macros-and-attach-them-to-all-documents/ […]


  2. […] Save your macros to a separate file and NOT to normal.dot — see this blog post of mine for full ‘how to’ details: https://cybertext.wordpress.com/2009/10/18/word-separate-out-macros-and-attach-them-to-all-documents/ […]


  3. […] documents etc. into a single macros file that you then include in your STARTUP directory. See https://cybertext.wordpress.com/2009/10/18/word-separate-out-macros-and-attach-them-to-al… for details. […]


  4. […] But what if you want to turn off that setting automatically for any document that you create or open? You can, if you add this to any AutoNew() (applies setting to new documents on creation) and/or AutoOpen() (applies setting to existing document on opening) macro in your template, or in a separate macros document that applies to all documents: […]


  5. Brilliant advice, thank you! For some reason the new macro was not available for a shortcut key to be assigned, however accessing the macro via the developer tab was fine.


  6. You don’t say how to add more macros to the new file.


  7. Hi tap17x

    You add macros to this file as you do for any other macros — i.e. through setting them up by recording them or writing them in VBA directly in the macro document, OR, if they already exist in another file, by using the Organizer to copy them across or copying them across manually.

    See these posts:

    –Rhonda


  8. hi.
    With Word 2010 (I have no way to check with previous or later versions), you can paste a _shortcut_ to your macro file in the STARTUP folder and Word2010 will manage to find the actual file. This might save duplicating the file and avoid possible confusion later on.


  9. Excellent idea, J! Thanks for sharing.


  10. I would like all the members of my organisation to use a macro. But I need to be able to update the macro without deploying the model each time. I know it was possible with Word 2002 but is it possible with Word 2010? Is it possible to save the model document on a shared location and not in the startup folder?


  11. […] Once you’ve created your table, save it to a location that your macro can pick it up from easily — I suggest somewhere on your local drive, not a network location (unless you intend sharing it with others). I put mine in my Word > STARTUP folder, which is where I keep my macros.dotm file. […]


  12. […] Add the macro below to an existing document, or better, an existing template, or even better, a central macros template that loads whenever you open Word. […]


  13. I suspect this solution only applies to manually-launched macros, as opposed to macros that run automatically when documents are created new from a certain template, e.g., to display a dialog box that collects required information and then initializes the document through find-and-replace of keywords. Such macros would still be associated only with specific templates, and to back them up, one would need to keep backup copies of the template file and/or the VBA code and forms code. This is a good solution, however, for macros that perform tedious, repetitive tidying tasks in an existing document.


  14. Hi Andrew

    Yes, it applies to macros you run manually. That said, one of my manual macros, which I’ve called ‘RunAll’ runs several of the other macros at once.

    –Rhonda



Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.