Written by Allen Wyatt (last updated July 12, 2025)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365
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 MarkLong1() Dim iMyCount As Integer Dim iWords As Integer If Not ActiveDocument.Saved Then ActiveDocument.Save End If iWords = 20 ' target word count iMyCount = 0 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 the macro starts by saving the document. This is done because long sentences are going to be formatted as red text, and saving makes sure you have a "pre-change" version saved. 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.
There is a drawback to this macro, though: The .Count property for the Words collection counts punctuation as individual words. Thus, the sentence "Really, she asked." would have a count of 5 words, instead of the 3 expected, because there are two punctuation marks. If you don't want punctuation marks included in figuring out the sentence lengths, then the macro needs to be lengthened just a bit:
Sub MarkLong2() Dim iMyCount As Integer Dim iWords As Integer Dim MySent As Range Dim iWordCount As Integer Dim sPunc As String Dim J As Integer iWords = 20 ' target word count sPunc = ".,?!;:-" ' don't count these as words iMyCount = 0 For Each MySent In ActiveDocument.Sentences If MySent.Words.Count > iWords Then iWordCount = 0 For J = 1 To MySent.Words.Count If InStr(sPunc, Trim(MySent.Words(J))) = 0 Then iWordCount = iWordCount + 1 End If Next J If iWordCount > iWords Then MySent.Font.Color = wdColorRed iMyCount = iMyCount + 1 End If End If Next MySent MsgBox iMyCount & " sentences longer than " & _ iWords & " words." End Sub
In this version, if the .Count property is greater than iWords, then a trimmed version of each word in the sentence is compared against a string of punctuation characters (sPunc). Only if the word is not within the punctuation string is it counted. It is this secondary count (iWordCount) that is finally compared against iWords and, if it is greater, the sentence is formatted as red.
Note:
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, 2021, 2024, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Finding Long Sentences.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2021 or Microsoft 365. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word Step by Step today!
Need to quickly put some text into a document, even if that text is essentially meaningless? Here's how to put this type ...
Discover MoreWant to select a chunk of text in a document? Perhaps the easiest way to do this involves using the mouse in conjunction ...
Discover MoreNeed to move a few paragraphs around in your document? Word provides a couple of handy shortcuts that make it very easy ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments