How to Create and Run a Macro in Word

It’s not just easy, it’s fun, too

If you work with Microsoft Word a lot and find yourself doing the same things repeatedly, create a macro. Macro is a shortening of the word macroinstruction, which means a series of instructions to accomplish a task.

The great thing about creating macros in Word is that you don’t need to know how to program. If you can press record and stop, you can do this.

Aren’t Macros Dangerous?

Have you heard about macros being bad because they can contain viruses? Although you do have to be careful about opening Office documents from unknown people because they might have malicious macros, that’s not an issue here. You make your own macro, so you know it’s not a virus.

How To Record A Macro in Word

For this example, you’re going to create a macro in Word toinsert your signatureat the end of a document.

How To Write a Macro

For most macros, the recording method is the most efficient way to create them. Eventually, you’ll want to do something more complex. This requires writing the macro in the Visual Basic for Applications (VBA) language. We’ve got thebest VBA guide for beginners, so bookmark that. Let’s create a macro to give us the average words per sentence to help us tell when we’re being wordy.

Dim s As RangeDim numWords As IntegerDim numSentences As IntegernumSentences = 0numWords = 0

For Each s In ActiveDocument.SentencesnumSentences = numSentences + 1numWords = numWords + s.Words.CountNext

MsgBox “Average words per sentence” + Str(Int(numWords / numSentences)) + “. Less than 15 is best.”

My Macro Doesn’t Work When I Save My Word Document

Word defaults to save with the file extension .docx, which doesn’t allow macros to automatically run. If you want the macro to run, you’ll need to change the file type to Word Macro-Enabled Document (*.docm).

This filetype exists partly to combat macro security issues. If you see this file extension on a document you weren’t expecting to receive, be suspicious.

What Else Can I Do With Macros?

You cancreate macros in Excel, Outlook, evenPowerPoint. Anything that you’re currently doing manually, you should be able to record or write a macro to do it. Using macros in Word along withgreat Windows shortcut keyswill amplify your productivity tenfold.

Guy has been published online and in print newspapers, nominated for writing awards, and cited in scholarly papers due to his ability to speak tech to anyone, but still prefers analog watches.Read Guy’s Full Bio

Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.

HomeAbout UsEditorial StandardsContact UsTerms of Use

Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved