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.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!
When getting rid of text from your document, Word allows you to delete, clear, or cut. Here are the differences between ...
Discover MoreWant to add some handy circles around text in your document? Believe it or not, Word provides three ways you can ...
Discover MoreWhen editing a document, Word normally selects entire words as you use the mouse to select text. This tip explains why ...
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