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 current sentence

Word • Macros • Editing
Peter Ronhovde
7
min read

Some of my favorite Word macros work with sentences like the standard keyboard shortcuts manipulate words or paragraphs.

I can't imagine why Microsoft didn't include more tools like this. There are some hidden commands, but we take them a step farther.

Thanks for your interest

This content is part of a paid plan.

How it’s usually done …

How do we usually delete sentences in Word documents?

Example of deleting a sentence with mouse

And how can we do this better with a VBA macro?

Create the empty macro

See a previous blog post where I went over the steps to create an empty macro. When you’re done, you’ll have something like:

Sub DeleteSentence()
' Delete the current sentence in the document

End Sub

Now it’s just patiently waiting for your amazing commands on the blank line.

Don’t forget the single quote on the second line tells Visual Basic for Applications (VBA) the rest of the text on that line is a comment meant for human readers.

Delete the current sentence

How do we delete the current sentence using a macro?

Example of deleting a sentence with our new macro assigned to a keyboard shortcut

Set the Selection

In past newsletters, we’ve been working with the Selection (see this article for more details) which is just VBAs representation of the same thing that we see when using Word. Specifically, we want to expand the selection to include the entire current sentence, so we can delete it.

Lucky for us, the command is almost exactly what we would think:

Selection.Expand

The only catch is the default for the expansion command is to expand the selection around the current word. We want the current sentence, so we need to tell the command the desired unit.

Here is where Word macros can feel a tad like programming. Not too bad though. The resemblance is there, but don’t worry. I’m guiding you the whole way, and you’re going to be editing faster when we’re done.

Specify the Unit

How do we tell the command the correct unit to use?

We literally give it a sentence Unit like so

Selection.Expand Unit:=wdSentence

The main units we’ll use in upcoming macros are: wdCharacter, wdWord, wdSentence, and wdParagraph; but there are more if you want to take a look at the list.

The unit constants all start with “wd” short for “Word” to distinguish them from other types of constants.

We had to use a := symbol to specify the Unit since it is technically assigning the sentence constant’s value to the parameter. If that doesn’t make much sense, it doesn’t really matter much. Just put the := when you are setting a value for a parameter in a command like this.

Finish the macro

Once we have the sentence selected, we just need to delete it.

Selection.Delete

Now put the two commands together, so the final macro is

Sub DeleteSentence()
  ' Delete the current sentence in the document
  Selection.Expand Unit:=wdSentence
  Selection.Delete
End Sub

I assigned this macro to Option+Shift+Delete on a Mac (or Alt+Shift+Backspace on Windows).

That’s it.

I think you’ll like these. I sure do. I use them often, and I can’t imagine why Word does not include them by default.

Now, go forth and edit faster!

Variations

Of course, you could cut or copy the selection if you prefer. I’ve included all three in my macros just to have the flexibility.

Sub CutSentence()
  ' Cut the current sentence in the document to the clipboard
  Selection.Expand Unit:=wdSentence
  Selection.Cut
End Sub

I assigned this to Option+Shift+X on a Mac (or Alt+Shift+X on Windows).

Copying the current sentence uses

Sub CopySentence()
  ' Copy the current sentence in the document to the clipboard
  Selection.Expand Unit:=wdSentence
  Selection.Copy
End Sub

which I assigned to Option+Shift+C on a Mac (or Alt+Shift+C on Windows).

Enhancements

Other things you could do improve the macro include handling parentheses or double quotes naturally, depending on the details of how you want it to work.

Personally, I remove any parentheses or double quotes from the initial expanded selection if the punctuation only occurs on one side of the sentence.

This may sound strange when you first read it, but it seems to provide an intuitive behavior when I’m working in a novel. That is, don’t delete the dialog quotes, for example, unless the entire sentence is dialog.

These changes are a little more involved, so they are relegated to a separate blog article for members.

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.