I often want to move around my document faster using more targeted navigation. That way, I don’t have to click clack around with the mouse and keyboard so much.
Quickly jumping to common punctuation marks definitely helps me navigate my documents faster.
Thanks for your interest
This content is part of a paid plan.
Create the empty macro
A previous article shows how to setup empty macros that include keyboard shortcuts, and a video for Word for Windows (Mac version coming soon) also covers how to add and modify keyboard shortcuts after macros are already created or when you've typed them manually.
Here is an example of an empty macro waiting for us.
Jump to punctuation mark
Just to prepare you, we’ll have four slight variations for navigating or selecting to punctuation because we need each option for both forward and backward in the document.
In the current context, I'll jump to nearby commas most often, so we’ll focus on them; but I’ve also created variations for parentheses, periods, quotes, and a few other punctuation marks.
The basic command to move the cursor (the blinking I-bar) to a specific character (or set of characters) is simple:
The MoveUntil command moves the edit location until it finds any of the characters in the list given for Cset. As advertised, I'm using a comma here.
As a reminder, the := symbol assigns Cset the given value. In this case, we assigned a character set off by double quotes. This is called a "string" (of characters) in programming circles.
Move backward
To move backward in the document, instead use:
Count is the number of characters matches to move (defaults to 1), but the wdBackward constant is a special case telling the command move backward to the first character in Cset that is found.
Multiple characters
You’re not limited to just one character. Add as many you wish.
For example, you might want to make your version stop at the next comma, period, or semicolon (perhaps so you have fewer keyboard shortcuts to remember). With this in mind, just add the extra characters to the Cset list within the double quotes.
There are ways to add other characters like tabs or paragraph markers if you want to be sure to stop on the same line.
Selection to punctuation marks
If you instead want to select all text up to the punctuation mark, the command is almost the same except you tell it to move the End marker of the Selection if you’re selecting forward in the document.
To select backward, move the Start of the Selection, but you have to tell it to count backwards like we did earlier.
Simple version issues
These simpler versions won’t jump past the character once it’s found the first time.
That is, if you hit the keyboard shortcut again, perhaps expecting to move to the next comma, the macro won’t move the edit location because it “finds” the character immediately.
See the extended version where we modify it to behave a little more intuitively in this regard.
Final Macros
The final versions of the macros are just one-liners.
Unfortunately, we need one for each direction for each combination of punctuation marks whether navigating to or selecting text. I’ve only included the variations for commas here.
Navigation
To jump to the next comma in the document, use:
Moving backward in the document:
I assign these to keyboard shortcuts Command+, and Option+, respectively, in Word for Mac, but I've also tested some other variations.
In Windows, I assign them to Control+, and Alt+, respectively.
Selection
To select from the current position to the next comma in the document, use:
Select backward in the document:
In Word for Windows, I assign this pair of keyboard shortcuts to Control+Shift+, and Alt+Shift+, respectively.
In Word for Mac, I've tried a few variations not being quite satisfied with the choices. Right now, I'm using Command+Shift+, and Option+Control+Shift+, respectively.
The asymmetry in the Word for Mac keyboard shortcuts is because it doesn't like some key combinations when using punctuation keys (see the Word for Mac caveat in the extended content for a little explanation).
Tweaks
Just to give some ideas of how you might tweak macros to match your own preferences, you might like to automatically select the whole first word even if you start in the middle of a word. In this case just add an expansion command at the beginning of your macro.
Personally, I have mixed feelings on Word automatically selecting whole words for me, but I have implemented similar things a few times in my own macros.
My personal implementation adds some position tweaks, so the cursor usually ends on the left side of the comma regardless of the direction of the jump. It’s more of a tweak, but the little niceties add up, and why not let the macro do it for me rather than having to hit more keys after I run the macro.
In the GotoPreviousComma version, I append this extra step to the end of the macro:
This has the nice side effect of allowing us to repeatedly run the macro to jump to successive commas when moving backward.
Final comments
With all four variants, you’ll have a nice little set of navigation and selection utility macros. Make whatever copies you like for the punctuation marks you prefer.
Unless you combine several into the same macro(s), you’ll need to have separate small macros for each punctuation mark, but your VBA editor doesn’t care how many macros you have stored.
Just implement the ones you know you’ll use. Other variations are easy to add later if you find yourself wanting them.
Managing a lot of macros will be easier later after we cover assigning keyboard shortcuts in a macro in members’ content.
I use these regularly, perhaps not as much as some of the others, but they're nice when you need them. Word really should include them by default.
Now go forth and edit faster!