Heading

This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
min read

Toggle Basic Formatting

Word • Macros • Editing
Peter Ronhovde
12
min read

I talk a lot about improving repetitive tasks when writing in Microsoft Word. Things we do thousands of times and probably don’t even realize they can be done more efficiently … if we only do a little up front work.

That’s why you have me here.

This macro applies basic formatting to the current word, so I don’t have to select the word first. It can be trivially extended to other character formatting types or other text blocks if you prefer something else.

All this creates a little spark of energy every time I make something easier. Give it a try.

Thanks for your interest

This content is part of a paid plan.

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:

Sub ToggleWordItalics()
  ' Italicize the current word

End Sub

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.

You can create a similar macro as ToggleWordBold formatting. As for other character formatting, I don’t use them much on an individual basis, so I omitted them in my own macros.

For anything more complicated, I usually use styles.

Why?

We all get in a rut of just doing things the way we already know. After all, it works, right?

Well yeah … but you could also mow your lawn with scissors. That works too.

The trick is to enhance the process without disrupting your workflow too much. We do want to make it faster in the end, so something has to be different, but it would be nice if we didn’t have to move mountains to make it happen.

I think the extended version of this macro below hits that sweet spot.

What are the manual steps?

Assuming there is no starting selection, what steps would we use to italicize the current word manually in Word? The fastest method is to use standard keyboard shortcuts.

  • Press Command+Left arrow to move to the beginning of the current word if you’re not already there
  • Press Command+Shift+Right arrow to select the word
  • Press Command+I to italicize the word

Of course, swap out the Command key for the Control key in Word for Windows.

Using the mouse is slower than it feels, but you could instead double click the word before applying the character formatting.

The above sequence of steps isn’t a deal breaker, but we're converting it into a single keystroke.

Selecting the current word

To select the current word at the insertion point for text, use

  Selection.Expand Unit:=wdWord

We’ve talked about this command several times, so briefly, it expands the current selection or insertion point to include the given Unit but no more.

The standard Word Units are most of the ones you might expect like words, paragraphs, sentences, etc.; but we want wdWord for this macro.

Toggling formatting

Turning Italics on

If you just want to assign italic format property, then use

  Selection.ItalicRun

This sets all text in the Selection to Italic whether it is already italicized or not.

Toggling is better

Personally, I like to toggle the formatting. It makes the macro feel more natural and makes it more useful in practice if you change your mind.

Toward this end, another method to assign italic formatting is to use the Italic format property of the Selection’s Range, and set it to True (on)

  Selection.Range.Italic = True

Slightly technical details

The Italic property is not strictly a True-False (called a Boolean) value, but we can mostly use it like one.

We did have to access the Range of the Selection since the Selection does not have an Italic property by itself.

If the range contains a mixture of italicized and not text then the Italic property will have a value of wdUndefined.

Rather than have some complicated logic to test whether the Italic property is True, False, or undefined and take steps accordingly, there is an easier way.

Toggling the formatting

Fortunately Word has a special toggle value for a Range’s Italic property we can immediately use

  Selection.Range.Italic = wdToggle

This command doesn’t toggle italics character by character. Rather it uses the formatting of the first character in the Range and toggles the italics state of all the selected text based on it. Most of the time this is what we want.

Final macro

There are only two steps for the basic version, so we get

Sub ToggleWordItalics()
  ' Toggle italics in the current word
  Selection.Expand Unit:=wdWord
  Selection.Range.Italic = wdToggle
End Sub

I assign this to Command+Shift+I in Word for Mac or Control+Shift+I in Windows.

This key combination makes the command similar to the default Command+I to just start italics or apply it to the current selection.

For any more complicated character formatting, I tend to use styles instead.

Recommend extended version

This is one where I definitely recommend the tweaked version, so please see the extended version below, if you’re interested.

Bold version change

Of course, the bold version is almost identical. Just create a new macro and change the line where you set the Italic property to instead change the Bold property

  Selection.Range.Bold = wdToggle

I assign this version to Command+Shift+B in Word for Mac or Control+Shift+B in Windows.

Improvements

Using the base macro above, I add several elements to my version to make it work more naturally and seamlessly in my documents.

Don’t touch the insertion point

I like to use a Range variable from the beginning, so I don’t disturb my starting position when I run the macro which is a nice little plus in my book.

We start by setting a working Range based on the current selection, and do the rest of our text manipulation with it

  Set MyRange = Selection.Range

Remember, when we store a Range we have to use "Set" because it is not a basic value like a number, plain text, or True/False.

When we need the current word, we use Expand with the Range much like we did with the Selection

  MyRange.Expand Unit:=wdWord

When we toggle the italics of the text in the Range, instead of using the Selection’s Italic property, we just use MyRange in its place

  MyRange.Italic = wdToggle

It ends up being no extra work and leaves us with the perk of not changing the insertion point position when we use the macro.

Allowing for selections

I prefer to italicize any starting selection like normal. That is, I only want my macro to select the current word if there is no text already selected when the macro is run.

We’ve covered this before, but we can test whether there is a starting selection or not using If statements and the Selection’s Type property. The two most important Selection Types are

  • wdSelectionNormal is a regular text selection.
  • wdSelectionIP corresponds to “no selection” in the intuitive sense when no text or other objects are selected in the document.

Specifically, Selection.Type will have one of these constant values (there are others for more complicated selections). See this supplementary article for more explanation since Microsoft’s descriptions are terse.

For this macro, we only do something different if there is no starting selection. We set the starting Range before and toggle italics after in either case.

  ' Do any steps before ...
  If Selection.Type = wdSelectionIP Then
    ' No starting selection, so select the current word
  End If
  ' ... finish any other steps.

Ignore blank space

I prefer to remove any spaces on the trailing end of a selection since Word includes them by default. To accomplish this, move the End of the Selection back to any non-space character.

After we’ve set the initial working Range, we can use

  MyRange.MoveEndWhile Cset:=" ", Count:=wdBackward

We’ve used MoveEndWhile before, so quickly, a Range includes a Start position and an End position defining its invisible extent in the document.

MoveEndWhile moves the End position of the selection, obviously, as long as the character at the End position is one of those listed in the Cset option (all characters inside the double quotes).

This command doesn’t delete the characters from the document. It just removes them from the Range.

The Count:=wdBackward option tells the command to move the End position toward the beginning of the document.

Don’t forget command options use := to store a value, and multiple options must be separated by commas. Most of the time, the option names and values are intuitive.

Applying italics to sentences

We can trivially extend the above macro to italicize a whole sentence.

Why?

Some writers like to use italicized text for inner dialog. Toggling it for a whole sentence will let you streamline the task or change your mind more easily about what is internal dialog or not as you’re writing.

The change is simple. Use the wdSentence Unit instead with the Range’s Expand command

  MyRange.Expand Unit:=wdSentence

Or if you prefer to italicize the current paragraph, use

  MyRange.Expand Unit:=wdParagraph

Final macro

Now put it all together for the nicer version of the basic formatting macro

Sub ToggleItalics()
  ' Toggle italics in the current selection or the current word
  ' if there is no selection

  ' Store the current Selection Range
  Set MyRange = Selection.Range

  ' Check whether a selection exists
  If Selection.Type = wdSelectionIP Then
    ' No starting selection, so select current word
    MyRange.Expand Unit:=wdWord
  End If

  ' Remove any blank spaces at the end of the selection
  ' (not essential)
  MyRange.MoveEndWhile Cset:=" ", Count:=wdBackward

  ' Toggle italics in the selection
  MyRange.Italic = wdToggle
End Sub

Again, I assign this to Command+Shift+I in Word for Mac or Control+Shift+I in Windows.

My personal version adds a few more tweaks to handle special cases that aggravate me, but the complexity to practicality ratio is too high to include here.

For any more complicated formatting, I tend to use styles instead.

Bold version change

Of course, the bold version is again almost identical.

Just create a new macro and change the Italic property toggle on the last line to Bold instead.

  MyRange.Bold = wdToggle

I assign this version to Command+Shift+B in Word for Mac or Control+Shift+B in Windows.

Affiliate Links

If you're interested in using Word or another tool related to the article, check out these affiliate links. I may make a small commission if you purchase when using them, but there is no increase in cost for you, and it helps to support this site and associated content.

I've been using Microsoft for Business for commercial use (that's us writers) on one of the lower pricing tiers for years. I get to use my macros, have online storage, and don't have to worry about software updates.