Creating an empty VBA macro
There are several ways to create a new empty VBA macro. We'll introduce three here.
The instructions vary a little between Word for Windows or Mac. While the included screen shots are for Mac, but the Windows versions are very similar.
If you prefer a video introduction, see this video on myYouTube channel, but it does cover more than just getting the empty macro created.
Thanks for your interest
This content is part of a paid plan.
What is a macro?
Macros are just text files with instructions for Word to follow automatically when the macro is "run."
Visual Basic for Applications (VBA) attempts to structure the commands as much like English as possible, but VBA does need a little extra description to define the various instructors to carry out on your document, so it knows exactly what steps to run.
Here, we’re creating the bare skeleton that specifies the beginning and ending a macro, so we can do some meaningful stuff in between later.
Word comes with a dedicated text editor to create and test VBA macros.
In VBA, macros are called subroutines which is shortened to “Sub” in the VBA editor.
Fastest method
Click the Record Macro button at the bottom right of the Microsoft Word window.
Immediately click the stop recording button without doing anything. Otherwise, Word will add the auto-generated command to your macro.
If you did do something before stopping the recording, it's not the end of the world. You can just delete the generated command when we get to the macro text in the editor below.
Then provide a name (step 1 below), decide whether or not you wish to assign a keyboard shortcut (step 2), and click or tap OK (step 3). Older versions of Word may include another option beside the Keyboard assignment.
Now add the keyboard shortcut to your new macro:
Press your desired keyboard combination using modifier keys Control, Command, Option, and/or Shift on Mac or Control, Alt, and/or Shift in Windows and another key (step 1). The description text right below shows you to what the key combination is currently assigned. Assign the combination (step 2). Then click OK (step 3).
You can also use the Customize Keyboard dialog to assign a keyboard shortcut to an existing macro. Just locate the macro in the list and make the assignment. There is also a way to automatically assign keyboard shortcuts in a macro, but that is beyond the scope of our mini-lesson here.
Almost as fast method
A similar method uses the ribbon. If you’ve ever recorded a macro before, this is probably how you started. Here is a quick animation:
Accessing the Empty VBA Macro
Whichever way you used to create the empty macro, you can access it by pressing Option+F11 on Mac (or Alt+F11 on Windows) to open the VBA editor. Your empty macro should be waiting on you.
If you have other macros, they will likely be there also above your new empty macro.
Comments
Note anything following a single quote character on a given line in the macro will be ignored by VBA when running the macro. We call this a “comment” which is often color coded in green in the text editor to make it easier to see and differentiate from the commands that VBA does run.
Easiest method
This method is little more technical but not too bad if you're nervous about that sort of thing.
Once you get used to the VBA editor, the easiest way to create a new macro is to just skip the recording step entirely and start by pressing Option+F11 on Mac (or Alt+F11 on Windows) to open the VBA editor. In the editor window below any existing macros, literally just start typing the macro like so:
Macro names can't have any spaces, and the only punctuation allowed is an underscore.
We'll cover how to add or update keyboard shortcuts for a macro later.
That’s it. We’ll get more details later, but you now have a new empty macro you can begin customizing.