h1

Word: Copying macros from one document to another when the Organizer doesn’t work

January 10, 2011

Scenario

You have a Word template with some useful macros. You’re setting up a new template unlike the previous one, but you want to use some of the useful macros that are contained in the first template. You try to use Word’s Organizer function but you get a message that The project item cannot be copied.

I think this message relates to situations where you try to copy containers for the macros (such as NewMacros and modMain) from one document to the other. But if the containers are the only options listed, you don’t have a lot of choice — and you can’t copy individual macros across using the Organizer.

What to do?

Possible solution 1

My first suggested solution is to put all common macros that you want to apply to all templates, 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-all-documents/ for details.

However, while this solution is fine for documents on your computer where you’re the only author, it’s not such a good solution when you want to distribute the template to others. With multiple authors and multiple computers, you should really keep the macros with the template — you can’t guarantee that other authors will put the macros file into their STARTUP directory, nor replace the file when a new one is created.

Possible solution 2

The second solution is to manually copy and paste the macros from Template A into Template B. This is fairly easy to do but it’s easy to get confused with where you are, so take your time.

Here are step-by-step instructions for doing this in Word 2007 (this looks like a long set of steps, but several steps are repeated for each macro container):

  1. First check if you can copy the macros from Template A to Template B using the Organizer. If you can’t, then continue following these steps. If you can, then skip to Step 18.
  2. Open Template A and Template B. NOTE: Open the templates, not documents based on the templates. Template A is where the macros are located; you’ll be copying them into Template B.
  3. In Template A, go to the Developer tab > Code group and click the Macros button.
  4. Select any of the macros belonging to this template, then click Step Into.
  5. In the top left panel of the Visual Basic window, locate the name of the TemplateProject you have open now (Template A’s name). Template B will also be listed (as may others); only choose Template A’s TemplateProject name.
  6. Expand it, then expand the Microsoft Word Objects and Modules folders of Template A. You should see ThisDocument under Microsoft Word Objects and modMain and NewMacros under Modules.
  7. Double-click ThisDocument in the top left panel to bring its window to the front in the right panel.
  8. If you want all the macros listed in this window, press Ctrl+A then Ctrl+C to copy them to the clipboard; if you only want some of these macros, then copy/paste them one at a time into the text file, making sure you capture the (Private/PublicSub and End Sub lines of each macro.
  9. Go to the TemplateProject name for Template B, and expand its folders.
  10. Double-click ThisDocument in the top left panel to bring its window to the front in the right panel. Remember, you should be working in the TemplateProject for Template B.
  11. Paste the copied text into Template B’s ThisDocument window.If there are existing macros in here you want to keep, go to the end of the window and paste the macros at the end.
  12. Go back to the Template A folders. Double-click modMain in the top left panel to bring its window to the front in the right panel. Copy the macros.
  13. Now go back to the Template B folders. Double-click modMain in the top left panel to bring its window to the front in the right panel. Paste the macros.If there are existing macros in here you want to keep, go to the end of the window and paste the macros at the end. Remember, you should be working in the TemplateProject for Template B.
  14. Go back to the Template A folders. Double-click NewMacros in the top left panel to bring its window to the front in the right panel. Copy the macros.
  15. Return to the Template B folders. Double-click NewMacros in the top left panel to bring its window to the front in the right panel. Paste the macros. If there are existing macros in here you want to keep, go to the end of the window and paste the macros at the end. Remember, you should be working in the TemplateProject for Template B.
  16. Save the changes to the Visual Basic window and close it.
  17. Save the changes to Template B.
  18. You may have lost your macro keyboard shortcuts to the macros –check first, then re-assign them in Template B, if necessary.
  19. Finally, test that the macros and your keyboard shortcuts all work as you expect. Debug as necessary.
  20. Do a final save.

See also:

[Links last checked January 2013]

5 comments

  1. […] This post was mentioned on Twitter by Rhonda Bracey. Rhonda Bracey said: New post: Word: Copying macros from one document to another when the Organizer doesn’t work « CyberText Newsletter http://bit.ly/fK6Axy […]


  2. About your comment “you can’t copy individual macros across using the Organizer” – I think you may be mistaken I do it all the time and I have about 15-20 macros that I copy right into documents themselves if I feel the need and not just templates.


  3. I meant to add to my previous e-mail above that I just use the Organizer in Word 2010 which makes it very easy



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: