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

Delete first word of sentence

Word • Macros • Editing
Peter Ronhovde
12
min read

Delete the first word of the current sentence without having to move the cursor.

I was embarrassed to share this one, but then I thought about how often I use it, and I had to share it.

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 DeleteFirstWordOfSentence()
  ' Delete first word of the current sentence

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.

This one overlaps the macro to capitalize beginning of the sentence.

Why?

This macro was a “productive procrastination” moment for me. I didn’t feel like writing that day, so I tricked myself into creating another macro. Something I kind of wanted to do anyhow, but at least I wasn’t just “researching” videos.

But this one has surprised me perhaps more many others. It’s not my most productive macro for sure, but I use it regularly.

What are the manual steps?

What steps would we use to delete the first word of a sentence manually?

  • Use the keyboard or mouse to move to the beginning of the sentence (mouse is slower than it feels)
  • Press Function+Command+Delete on a Mac or Control+Delete in Windows to delete the first word.
  • Delete and then replace the first character of the new first word of the sentence
  • Move back to the original editing location

No standard keyboard shortcut exists to navigate between sentences in Word, but a previous article covers how to assign keyboard shortcuts to several default Word commands to do this.

Doing the above steps in today’s macro would be clumsy and unnecessary, but it's a starting point to think about the macro.

In a soapbox moment, I really wish Apple would fully support the “forward” Delete key (the Unix base for MacOS does). It’s a holdover from reduced-size keyboards, but it really would be nicer to have both Backspace (Delete on Mac) and forward Delete keys especially when we’re setting up keyboard shortcuts for macros.

Requires Ranges

If we’re going to do this without moving the insertion point, the easiest and probably best way is to use Ranges.

See this article for a brief introduction to Ranges.

Briefly, a Range is a span of content in a document acting much like an invisible Selection. Most of their respective methods and properties are very similar.

Several steps are duplicates of steps in the previous capitalize first word of the sentence macro, so I’ll move fast on those.

Set the current document position or selection

Since we're using Ranges, we need to store the current insertion point position in the document using the Selection's Range.

  Set MyRange = Selection.Range

Once we have the position, we can work with it much like we’ve done previously with the Selection.

Recall we must "Set" the Range (since it contains other information than just a value) rather than just use an equals "=" sign like we can with other values such as text strings and Case values (see below).

Move to the start of the sentence

We’ve used StartOf before with the Selection. The command is basically the same for Ranges.

  MyRange.StartOf Unit:=wdSentence

Remember StartOf doesn’t move the insertion point if the position is already at the start of the given Unit.

The Unit constants include most of the common ones we think of when creating documents (e.g., words, sentences, paragraphs, etc.). This one uses Word’s standard sentence constant.

Delete the first word

The new step is to delete the first word.

  MyRange.Delete Unit:=wdWord

Remember Delete acts like the keyboard’s Delete key, so the default is to delete forward in the document by one character, but we can also set a Delete unit.

Capitalize the new first word

I wrote about this in some detail in the previous article, so I’ll be quick here.

Even though there is no spanned text in MyRange, we can still capitalize the immediate word at the Range position using the Case property of the Range.

  MyRange.Case = wdTitleWord

There is a standard list of Word VBA Case constants, but we basically only need this one or wdTitleSentence on occasion.

Finish the macro

Now put the commands together.

Sub DeleteFirstWordOfSentence()
  ' Delete first word of the current sentence
  Set MyRange = Selection.Range
  MyRange.StartOf Unit:=wdSentence
  MyRange.Delete Unit:=wdWord
  MyRange.Case = wdTitleWord
End Sub

I assigned my version of this macro to Command+Option+W in Word for Mac or Control+Alt+W on Windows.

The nice thing about using MyRange is the macro leaves the insertion point alone. You can just keep working where you are.

See the extended content below to ignore double quotes with dialog.

Any gotchas?

Anytime you’re deleting things, you should probably think a little harder about potential problems. I know as a writer, I definitely don’t want to lose content.

Fortunately, the gotchas are nominal this time. At worst we lose a word, but even that’s very unlikely to happen.

Starting selections?

A typical gotcha consideration for most text-oriented macros is whether there is a starting selection, but does it matter here?

Would don’t really care if there is a starting selection since we move to the beginning of the sentence with MyRange as the first step. This automatically collapses the range just like it would with the Selection (Start is the same as its End position) anyhow.

Improvements

Skip dialog and parentheses

We’ve accounted for this before in previous macros, so we’ll move a little faster this time.

As a writer, allowing for double quotes at the beginning of a sentence is an important addition. I don’t want to delete them when I delete the first word.

While we’re already solving the problem, we’ll also skip an open parenthesis as an easily added bonus.

Stepping past any starting punctuation marks

We have to move past those characters from the start of the Range, but unfortunately for our macros, a left double quote is different on Mac and Windows systems.

On a Mac use:

  MyRange.MoveWhile Cset:="[(" + Chr(210) + Chr(34)

In Word for Windows use instead:

  MyRange.MoveWhile Cset:="[(" + Chr(147) + Chr(34)

If you’re comparing the step to the previous article, you may notice I used MoveStartWhile there. In that case, MyRange spanned some text, so we had to modify the beginning of the Range.

This macro uses MoveWhile because at this point in the macro, MyRange is just a single position in the document (Start is the same as its End position). We just need to move the MyRange position past the punctuation marks.

Finish the macro redux

Here is the revised macro allowing for dialog or parentheses.

Sub DeleteFirstWordOfSentence()
  ' Delete first word of the current sentence
  Set myRange = Selection.Range
  MyRange.StartOf Unit:=wdSentence
  MyRange.MoveWhile Cset:="[(" + Chr(210) + Chr(34)
  MyRange.Delete Unit:=wdWord
  MyRange.Case = wdTitleWord
End Sub

I assigned this macro to Command+Option+W in Word for Mac or Control+Alt+W on Windows.

Swap out Chr(210) for Chr(147) in Word for Windows, so skipping the initial left double quote works correctly.

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.