Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Finding Long Sentences.

Finding Long Sentences

by Allen Wyatt
(last updated June 8, 2015)

7

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 (3381) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) 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

Forcing the Properties Dialog Box to Appear

Do you want the Properties dialog box to appear when you first save a Word document? You can configure Word so that it does ...

Discover More

Spell-checking Uppercase Words

Excel's spell-checker normally checks uppercase words for spelling. If your worksheet contains a lot of acronyms, you might ...

Discover More

Editing Word's Built-in Commands

Want to configure Word to do just what you want it to? You can even go so far as to change the actual way in which Word ...

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 (menu)

Running Macros Based on Keywords

Wouldn't it be great if Word could execute a macro every time someone typed in a particular keyword or phrase? Word may not ...

Discover More

Cleaning Up Text in a Macro

Need to remove extraneous characters from a text string? VBA makes it easy through the CleanString method, described in this ...

Discover More

Aligning a Paragraph in a Macro

If you are applying formatting from within a macro, you may want to change the alignment of various paragraphs. Here's how ...

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. 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 two minus 2?

2016-05-16 19:31:18

Peter Thomas

This may be useful. I have had trouble over the last couple of years getting documents to preview in Windows explorer. Searching on the Internet leads me to believe I'm one of many. Today I solved my problem and it may be useful to others: - This is for Word 2016

1. Open Windows Explorer.
2. Click to the View tab.
3. Click on Preview Pane.
4. Go to the right hand side and click Options.
5. Click on the selection that drops down.
6. In the Folder Options dialogue box click on View
7. Scroll down and click the check-box for "Show preview handlers in preview pane".
8. Click Apply and OK. The preview for will now show in the Preview Pane of Windows Explorer.

I hope this can be of value to you and your readers.

Cheers

Peter Thomas
pfthomas@aapt.net.au


2015-04-22 08:13:47

Doug P

Just wanted to say thanks - this is great.

I'm an academic with a bad habit of writing long sentences and love the simplicity & flexibility of this.

Thanks for making and sharing this, you've made something that is useful. I hope you derive some satisfaction from knowing that!

Doug.


2013-11-13 04:16:50

Wende

Hi,

I am experiencing the same problem as beyondnerd. Is there a way to exclude puctuation marks from the sentence?

Please please help!


2013-04-24 16:47:23

beyondnerd

I just noticed a problem. The value of MySent.Words.Count seems to include the number of words plus the number of punctuation marks (commas, quotation marks etc.).Consequently the following 19 word sentence (for example) is marked as having over 20 words.

After the yellow sun goes down, beyond the horizon, the quick brown fox jumps over the fat lazy dogs.

Is there a way to get the actual word (not including punctuation count)for each sentence? The word count function on the review tab gets the correct count.


2013-04-15 01:49:40

beyondnerd

Very helpful, thank you


2013-03-03 10:38:36

José de la Riva

Hi, Allen. I´m having problems with this macro, because my Word 2007 doesn´t understand "'Set number of words". In Visual Basic, it´s highlighted in red, as other commands I´ve found in Jack Lyon´s Macro Cookbook. Is it due to my version of MS Word? Will it work in more recent versions of the program, like Word 2010? Thank you!


2012-11-23 05:58:41

Sam Hale

Really useful, thanks!


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon 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.