Please Note: This article is written for users of the following Microsoft Word versions: 2007 and 2010. 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

by Allen Wyatt
(last updated May 16, 2016)

5

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.

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 and 2010. 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 the Drawing Grid

One of the lesser-known drawing tools provided in Word is the drawing grid. You can easily turn this feature on and use it to ...

Discover More

Getting Rid of Non-Printing Characters Intelligently

Is your worksheet, imported from an external source, plagued by non-printing characters that show up like small boxes ...

Discover More

Using the Copy or Move Text Keys

Most people use the Clipboard to copy and move text in Word. Before the Clipboard, Word used F2 to move text and Shift+F2 to ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Repeating Your Typing

Want a quick way to repeat a word or phrase you just typed? Here's the shortcut you need.

Discover More

Overcoming Automatic Word Selection

When you select text with the mouse, Word usually selects entire words for you. If you don't want to do this, you can use the ...

Discover More

Deleting All Text in Linked Text Boxes

Word allows you to place text in multiple text boxes and have that text flow from one text box to another. This tip explains ...

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}] 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 7 + 6?

2016-11-23 07:37:59

Joe

Thanks for this, works great!

If I then go and change some of the sentences to less than 20 words and run the macro again, is there any way to change the sentences that are less than 20 words back to black, rather than staying red?

Thanks!


2014-11-26 15:20:14

Darin Ramsey

Allen--
This is very useful for us, as our group supports a large engineering organization on a Federal project. I've altered your macro to pull the average sentence length from the readability statistics, double it, and change those sentences red. Unfortunately, it appears to be counting punctuation as "words." In a document with an average sentence length of 20.3, a sentence with 37 words (according to the GUI) and five internal marks (a set of parentheses, a semicolon, and two commas) was going red until I removed four of the marks. Which four doesn't make any difference, so it seems to be counting all of them. Do you have any advice on getting the VBA word count to more accurately align with Word's GUI count? The changes in the code are as follows:

After the save, insert this:
Set myRange = ActiveDocument.Content
wordval = myRange.ReadabilityStatistics(6).Value

When setting the iWords value, use this:
iWords = wordval * 2


2013-12-18 02:32:27

Rochelle Fisher

We got an error on the first run, that MySent is not defined. Added: Dim MySent As Object

(At first, defined it as Sentences, but that caused other problems.)


2013-11-26 21:53:50

aiway

hi !
how do i get it to undo the red marks on my file ?
thanks !
a


2013-10-17 14:22:58

Mike Korner

Just wanted to say thanks for this Allen. It was helpful today.


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.

Newest Tips
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.