Manually assigning shortcuts to our writing and editing macros becomes tedious after we accumulate more than a few of them, so we create a macro to automatically assign them for our macros. Having a central location for the shortcuts will further allow better organization, so we can more easily remember and use them. A slight tweak also assigns shortcuts to any standard Word commands.
Thanks for your interest
This content is part of a paid plan.
Add a shortcut in a macro
Word shortcuts can be added manually through the keyboard customization options, but after we accumulate more than a few writing and editing macros, we’ll be clamoring for an automated way to assign shortcuts to our macros. In this article, we create a macro to automatically assign shortcuts to our own macros or even standard Word commands.
The command to add shortcuts in Word VBA is a tad clumsy, so a separate member article series makes the process easier at the expense of needing a lot more work to get to the finish line.
Manually add a keyboard shortcut
We can manually add shortcuts through the Word interface, but the method depends on the platform. The customization dialog is buried in Word for Windows, but this video covers the steps to access it. In Word for Mac, we access it through the Tools menu. It is more a streamlined than the Windows approach, but it still requires a manual assignment for each shortcut.
Why automate the process?
Manual works, but it’s tedious for anything more than a few customized keyboard shortcuts.
More importantly, Word will occasionally spontaneously reset some or all custom shortcuts. The most likely culprit is when the Normal.dot global template becomes corrupted and is automatically regenerated by Word. Another case that has bitten me a few times is the VBA editor will cancel a custom shortcut if you happen to copy and paste a macro within the VBA editor. The editor doesn't understand you're about to change the name to create a new macro. In the moment, it doesn't know which macro to use, so it just cancels the shortcut. Then three days later, you're wondering why it isn't working.
Having a quick way to reset all of them at once is not just nice, it’s almost essential if we plan on using them regularly.
Common terms with custom shortcuts
“Key binding” is connecting a particular key combination to an action. It's not specific to Word, but in our case, it's assigning a particular key combination to execute a specific macro or Word command.
A “modifier key” is one of the special keys we use for keyboard shortcuts.
When necessary, I may use the term "main key" to distinguish between the modifier keys and the other key pressed with a shortcut. For example, I have a shortcut Control+Shift+Delete assigned to a macro to delete the current paragraph. Control+Shift are the modifier keys, and Delete is the main key.
Key combinations
On Windows, we can use Control, Alt, and/or Shift as shortcut modifier keys with most other keys. The Windows modifier key is special for the operating system (but not entirely). Word technically does not allow access to the Windows (Win) command key for shortcuts in Word, but a separate article uses PowerToys for a workaround.
Macs allow up to four modifier keys specifically the Command, Control, Option, and Shift keys. In principle, we can assign any combination up to all four using the manual approach, but the key code function below only allows up to three modifier keys (our member article version allows all four). The extra modifier key on a Mac is nice when setting up some shortcuts, but we probably won't use all four of them often.
For brevity, I will not refer to Word for Windows or Word for Mac very time. Any shortcuts that refer to the Command or Option keys are used in Word for Mac. Likewise, any shortcuts that refer to the Alt or Win (not supported by Word) keys are necessarily used in Word for Windows.
Problem key combinations
On both Mac and Windows, some limitations exist for which key combinations work, but the specifics vary. Part of the problem is related to how the operating system interprets keyboard input.
Windows fusses occasionally about the Alt key being used with some combinations perhaps because it is also tied to menu access and special character input as legacy features. Some applications, such TextExpander, may also not play nice with shortcuts when using the Alt key (not clear why).
Word for Mac seems to dislike combining the Shift and maybe the Option key when interpreting certain key combinations usually involving punctuation marks.
Test any unusual combinations using the manual approach mentioned above before adding them to the automated macro.
Create the empty macro
A previous post covers creating an empty macro like the one shown below. When you’re done, you’ll have something like:
The single quote tells VBA the rest of the text on that line is a comment meant for human readers. We start our macro steps on the empty line.
Add a macro shortcut in Word
Our goal is to automatically bind a keyboard shortcut to our choice to a macro, but we have several components of the command to work through. The result is a little messy, but it works.
What steps are needed to assign a shortcut?
As a quick overview, we need several pieces of information to add or reassign a shortcut:
- Use the Add method of the KeyBindings collection
- Decide on the category of the shortcut assignment (usually a macro but sometimes a command)
- Find the macro name as plain text
- Determine the unique key code corresponding to the desired shortcut
Add a keybinding
The command to add a new key binding command starts with the Keybindings collection of the Word Application.
Technically, it is a property of the Application object, but we can omit Application since VBA will assume it.
We want to add a key binding using its Add method.
Pick a shortcut category
KeyCategory is the type of command or action being mapped to the shortcut. The main categories applicable for us are:
- wdKeyCategoryMacro – Assign the upcoming shortcut to one of your own macros
- wdKeyCategoryCommand – Assign the upcoming shortcut to one of Microsoft’s standard Word commands (the list is found in the manual entry dialog box mentioned up top)
Others you might use at some point in the future are:
- wdKeyCategoryDisable – disable a keyboard shortcut
- wdKeyCategoryAutoText – assign a keyboard shortcut to an AutoText entry
- wdKeyCategoryStyle – Assign a style with a shortcut (I prefer to just create a macro)
Assign the shortcut category
These categories are defined in a Word key categories constants table.
We assign the desired constant to the KeyCategory option. For us, the wdKeyCategoryMacro constant is probably the most common category. All option assignments require a colon equals := symbol.
Assign the command name
Which command or macro are we assigning to the keyboard shortcut?
For both macros and Word commands, we just assign the name as plain text inside double quotes.
This is easy for our own macros because we usually named them. Macro and Word command names cannot include any spaces.
Finding standard Word command names
Finding the name of a particular Word command you want to reassign can be challenging since they are abbreviated names and documentation is difficult to find. The commands are listed in the respective Word for Windows or Mac manual shortcut assignment dialog. Various command subgroups exist as well as an All Commands group, so peruse the lists and perhaps test a few that look right.
Test to make sure it does what you think it does. Microsoft Copilot can shed some light on particular commands, but it understands better if you ask about a specific command rather than a command that performs a particular task. On the latter, it gets sidetracked by all the normal way to do the task in Word.
Assign the shortcut keycode
The KeyCode is a number that acts as a unique key combination identifier. This is slightly more complicated, but they give us a way to “build” a key code that represents the shortcut combination.
Using constants from a standard Word keys table, pack the desired modifier keys and the main key into the BuildKeyCode function below. It accepts up to four total keys, zero to three modifier keys and the main key. Assign this value to the KeyCode option in the key binding add method above.
BuildKeyCode function
The BuildKeyCode function looks like:
The order does not matter, but we often list the modifier keys first. Most of the key constants follow the pattern wdKey followed by a letter, number, or relatively obvious key description. If you’re using a regular key (letters, number, some punctuation marks, etc.), include at least one modifier key. Overriding the "A" key to run a macro is asking for trouble. The exception is if you’re mapping to a function key since they are .
On Windows
For Windows, the key values corresponding to the modifier keys are: wdKeyControl, wdKeyAlt, and wdKeyShift
On Mac
For Mac, the key values corresponding to modifier keys are: wdKeyCommand, wdKeyControl, wdKeyOption, and wdKeyShift.
No more than four keys are allowed in the BuildKeyCode function, including the main key. This is why we can’t automatically assign all four modifier keys, Command+Control+Option+Shift, along with some other key on a Mac. However, we can still manually assign such a shortcut.
Despite the numbers listed in the documentation, the Word for Mac values are different for some modifier keys.
BuildKeyCode details
The BuildKeyCode function seems to just add the numerical key values together, but it does some validation checks before returning the result. The member article version allows automatic assignments of all four modifier keys in Word for Mac shortcuts, but you could easily DIY it for those few shortcuts, if you wish.
Assign the macro shortcut
A typical key binding command might look like
Well, that’s a doozy.
The underscore _ character at the end of the first line tells VBA to continue the long command over into the next text editor line. Basically, VBA treats it like on long line, but we can read it in the editor with two lines.
This key binding example would add the Word keyboard shortcut Control+Alt+M on a Windows system to a macro called MyMacroName.
Does not erase another shortcut
This command will override a existing shortcut assigned to Control+Shift+M to make this shortcut invoke the new macro, but it will not erase any other shortcuts assigned to run the MyMacroName macro. Meaning, you can have more than one shortcut assigned to the same macro or command.
Assign a Word command shortcut
The command can also (re)assign some of the standard Word commands.
- Swap the key category to wdKeyCategoryCommand
- Find the Word command name (sometimes a challenge)
For example, I’ve grown accustomed to the more Mac-like Control+Shift+Z for the Redo/Repeat keyboard shortcut. Another application uses this key combination for Redo, and my muscle memory with the Windows-flavored Control+Y was giving me fits at times. I simply added the second version into my shortcuts macro.
With this reassignment, I can use either shortcut.
Final Macro
Unlike many other macros, this one is a skeleton you can fill based on your own writing and editing shortcuts toolbox.
This first key binding command would assign the Word keyboard shortcut Control+Alt+M on a Windows system to a fake macro called MyMacroName. The second command assigns Control+Shift+Z to the standard Word Redo/Repeat command.
As your list of shortcuts in your editing toolbox grows , which will happen faster than you might think, this will get messy fast. Our member article significantly simplifies the shortcuts (re)assignment process at the cost of requiring more work to initially implement.
Shortcut organization
As your number of writing and editing macros grows, it helps to have a reasonable system to organize the shortcuts for our fingertips. If you can't or don't remember them, you won't use them. Here are a few suggestions.
- Be (somewhat) consistent with Word shortcut patterns. For example, I reserve (kind of) the Shift key for macros somehow related to selections, but I extended the idea to macros that automatically act on a range of text.
- Use the Alt or Option key to manipulate sentences much like Control or Command tends to work with paragraphs or words (yeah, occasionally a page also).
- Use Command+Option or Control+Alt to manipulate words or heading content.
- Lean toward existing standard Word shortcuts you already remember. For example, I assigned my automatic spelling error correction macro to Control+Shift+F7 or Command+Shift+F7 because the F7 key is already connected to several standard spelling and grammar related shortcuts.
Word has some disparity with its own standard shortcuts. The defaults did not cover as many useful categories as our collection of editing macros. Other general tips include:
- Currently assigned shortcuts can been seen in the respective manual assignment dialog mentioned above.
- Macros or Word commands can have more than on assigned shortcut.
- Don't be afraid to override any standard Word shortcuts you rarely use if it fits with your organizational scheme. You can always clear them back to the defaults later, if needed.
- Try to pick shortcut combinations that don't contort your fingers when you use it. However, I make exceptions for lesser-used macros that I still want at my fingertips.
Of course, these are just suggestions. The whole point is edit faster not get bogged down in the process. It will never be perfect because we only have so many keys, but you can still have many of your favorite editing macros right at your fingertips.
What else can I do to edit faster?
Other lesser-used tips include:
- Shortcuts can be mapped to Function keys up to F16 even though modern keyboards only include up to F12. Not all combinations work, but this can allow additional combinations for macro keys on a fancy keyboard (Logitech has several keyboards like this) or an Elgato Stream Deck. This is next level stuff though, so stick with what’s comfortable at first (probably for a long time).
- Shortcuts can be assigned to trigger AutoText entries (like scene setting boilerplate text), assign styles, insert symbols, and make font modifications.
- We can also create two-key shortcuts, like when accessing the Word menu system with the keyboard.
As you get more into macros, you might implement voice recognition commands in Word. This is a more complex topic, but it also opens the door to many more avenues of writing and editing optimization. We have several articles introducing VBA in Dragon Naturally Speaking (not an affiliate) voice commands. It is a paid application with a significant price tag, but check out the introductory article, if you're interested in pursuing that route.