Word: Separate out Macros and Attach Them to All Documents

Word: Separate out Macros and Attach Them to All Documents

Word: Separate out macros and attach them to all documents

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

I needed to make some macros available to all Word documents I opened. 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 > 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:
  3. Word 2003: C:\Users\<UserName>\Application Data\Microsoft\Word\STARTUP
  4. Word 2007 and later: C:\Users\<UserName>\AppData
    \Roaming\Microsoft\Word\STARTUP
  1. You can check your Startup folder location here:
  2. Word 2003: Tools > Options > File Locations tab. Select Startup, then click Modify to see the full file path.
  3. Word 2007: Office button > Word Options > Advanced > General section (near the bottom). Click File Locations, then select Startup. Click Modify to see the full file path.
  4. Word 2010 and later: File > Options > Advanced > General section (near the bottom). Click File Locations, then selectStartup. 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!