What to Do with Macro Code in Microsoft Word

Somebody gave you some code to use, but you don't know what to do with it? This should help, though you may require more information than they gave you. These are general instructions and won't likely work for everyone under every circumstance.

For All Documents

If you want the code to be able to run in any document, then it must be stored in a global template. Some people will tell you not to use normal.dot, which is the default global template. However, I think it's fine to use it, but you should read about normal.dot, understand it, and protect a copy of it.

Open Word. Hit Alt+F11 or ToolsàMacroàVisual Basic Editor (VBE).

If you don't see it as shown in the screen capture above, you may need to choose from the menu, ViewàProject Explorer, and ViewàCode.

On the left, select Normal.

From the menu, choose InsertàModule. The new module appears and a code window appears at right.

Paste the code you were given in the code window at right.

Hit the Save diskette on the toolbar. This saves normal.dot regardless of any other settings. Click here to learn how to assign the macro to a toolbar button or shortcut key.

For a Single Document

Use the same instructions as provided For All Documents, except instead of choose Normal from the Project Explorer window, you must open your document, go to the VBE and choose Project (Your Document). You'll still insert a module, etc.

Run When the Document Opens or Is Newly Created

Whether you use it for all documents (place the code in Normal) or only for a specific document (place in the single document), you can run code when a document opens or when a document is newly created.

Double-click the document. We have chosen Document1. Then, from the drop-down at the top of the code window, choose Document.

A new Document_New procedure is created for you, but no code is provided. Document_New will only work if your document is a template. The Document_New event is fired when a new document is created from a template. Change "New" to "Open" to have it work when the document is opened.

You may need to take the code provided, remove the first and last lines, and paste the remaining code between the Private Sub... and End Sub lines in the code window.

Don't forget to hit the Save diskette.

OfficeArtilces.com debuted on May 26, 2005.

MrExcel.com provides examples of Formulas, Functions and Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Formulas, Functions and Visual Basic procedures on this web site are provided "as is" and we do not guarantee that they can be used in all situations.

Access®, Excel®, FrontPage®, Outlook®, PowerPoint®, Word® are registered trademarks of the Microsoft Corporation.
MrExcel® TM is a registered trademark of Tickling Keys, Inc.

All contents © 1998-2014 by MrExcel Consulting | All rights reserved

© Copyright 2018 officearticles.com.