Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Writing a Macro from Scratch.

Writing a Macro from Scratch

Written by Allen Wyatt (last updated July 27, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


1

Many of the tips used in WordTips rely upon macros in order to run. Some readers may not know how to enter a macro from scratch in Word. There are actually two ways you can create macros. First you can record a macro, which is appropriate when you want to record a series of steps you perform quite often. The second method of creating a macro, writing one from scratch, is much more powerful.

To create a macro from scratch, follow these steps:

  1. Make sure the Developer tab of the ribbon is displayed.
  2. In the Code group, click Macros. Word displays the Macros dialog box. (You can also display the Macros dialog box by simply pressing Alt+F8.)
  3. Using the Macros In drop-down list (near the bottom of the dialog box), select where you want your new macro stored. Select Normal.dotm (Global Template) if you want your macro available in all documents; select a different template if you want the macro available only with that particular document template. You can even assign a macro to a specific document.
  4. In the Macro Name box, type a descriptive name you want assigned to the macro you are writing. (Make sure the name doesn't have any spaces in it.) Optionally, you can enter information in the Description box.
  5. Click on Create. The VBA Editor is started and you can write your macro.
  6. When you are through, close the macro window by selecting the Close and Return to Microsoft Word option from the File menu, or press Alt+Q.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (6821) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Writing a Macro from Scratch.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Entering Characters with Diacritical Marks

Entering characters that use diacritical marks is easy as pie in Word and some other programs. Not so in Excel, it takes ...

Discover More

Segregating Numbers According to Their Sign

Remember your number line from your early years in school? Some numbers can be below zero (negative numbers) and others ...

Discover More

Sorting Decimal Values

Government and industrial organizations often use a numbering system that relies upon a number both before and after a ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Setting the Right Indent of a Paragraph in a Macro

Need to format your document using a macro? You can easily set the right margin for an individual paragraph by using the ...

Discover More

Printing a Macro List

Need a list of all the macros you've created? Word doesn't provide a way to create such a list, but you can use the ...

Discover More

Selecting to the Next Punctuation Mark

Writing macros often involves selecting different parts of your document so that some sort of processing can be ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 - 6?

2020-03-31 08:25:34

Pia

Hello,

I have to write a macro to change the branding and the structure of a word document (method of procedure - MOP) based on the following requirements:

1. We have a MOP document written in our company's template. The client, however, wants the same document in their company's format. So, we need to rebrand the document per the client company's template.

2. We also need to make changes to the placement of content. For example, in our document, there is a section called "Pre-installation Checks". The content from this section needs to go into a table in the Client's document. So, it means we need to make structural changes to the document.
There would be more such structural changes throughout the document. I can work on those if you can provide an example for one such change.

The idea here is for the engineers who are not very familiar with Word to work on these documents with just a click of the macros.

Could you please help with writing a macro for these two requirements?

Thank you!


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.