Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Finding Long Sentences.

Finding Long Sentences

Written by Allen Wyatt (last updated October 3, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


6

Bruce is looking for some way to have Word automatically mark long sentences in a document. For instance, he may want to have those sentences with more than 20 words marked in some color so that they are easily located.

Fortunately, Word maintains a Sentences collection, accessible through VBA, that consists of each sentence in a document. You can examine each item in this collection (each individual sentence) to determine if it is longer than your desired length. The following macro provides an example of how this is done.

Sub Mark_Long()
    Dim iMyCount As Integer
    Dim iWords As Integer

    If Not ActiveDocument.Saved Then
        ActiveDocument.Save
    End If

    'Reset counter
    iMyCount = 0 

    'Set number of words
    iWords = 20

    For Each MySent In ActiveDocument.Sentences
        If MySent.Words.Count > iWords Then 
            MySent.Font.Color = wdColorRed
            iMyCount = iMyCount + 1
        End If
    Next
    MsgBox iMyCount & " sentences longer than " & _
      iWords & " words."
End Sub

Notice that each sentence is examined, and if it is longer than the desired length (defined by the variable iWords) then the sentence is changed to a red font color. This makes it easy to examine the document and discover which sentences exceed the length you specified.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11909) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Finding Long Sentences.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using AutoShape Connectors

If you add AutoShapes to the drawing canvas, you can use connector lines between those shapes. Here's how to add them to ...

Discover More

Getting Bookmark Information in VBA

Bookmarks are a handy way to "mark" locations within a document. If you are creating a macro that processes the document ...

Discover More

Entering a Name in the Header of a Locked Form

When you lock a document as a form, then Word limits what you can do with that document. That includes not being able to ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Jumping to the End of a Word

Using shortcut keys to navigate through your document is really handy. One navigation shortcut that Word doesn't provide ...

Discover More

Moving an Entire Page

If you are new to using Word, you may wonder if there is an easy way to move pages around in the document. Word, though, ...

Discover More

Stepping through Sentences

Need to select an entire sentence at once? You can do so by creating a short macro that does the task for you, or you can ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three more than 1?

2021-09-10 09:16:26

Ken Blair

Thank, KE. I'll work on getting the results into an array so I can place in a document.


2021-09-09 04:19:16

KE

To Ken Blair
The following example searches for the text "mytext", selects the surrounding sentence and displays the text of the sentence in a message box.

Sub SentenceContainingFind()
With Selection.Find
.ClearFormatting
.Execute findtext:="mytext"
End With
Selection.Sentences(1).Select
MsgBox Selection.Range.Text
End Sub


2021-09-08 14:59:19

Ken Blair

Alan,

What does Word use to demarc the sentences? I have a need to modify your VBA to search for a certain word's occurrence and then extract the sentence that contains it. Knowing the demarcs might make that an easier process.


2021-09-07 13:10:41

MZ

Using MS Word 2019 and the above macro, but it is miscounting the words. It appears that it is also counting punctuation as its own word (and maybe format codes too). This creates too many false markups. Any way to have Words.Count number match the MS Word value for the same sentence?


2021-06-17 03:30:45

soja

Thanks Allen for your VBA
best regards


2020-01-18 08:12:55

Patty

Thanks, Allen, for this sweet tip. If I used this macro in most documents I edit, all the text would be red! Unfortunately, I'd have to use 50 as the cutoff (iWords = 50 in the macro). But this would be a great pre-editing tool to analyze just how dense the prose is. In other words, "Red text cannot easily be read"!


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.