When you grammar check a document, you can elect to display the document’s readability statistics. (Select Office, Word Options, click Proofing, and activate the Show Readability Statistics check box.) Among other values, the Readability Statistics dialog box offers the average number of words per sentence. This is useful because you don’t want your average sentence to be too long or too short. However, writing gurus also stress that you should have a variety of sentence lengths in your prose, with some shorter and longer sentences thrown in for reading variety. Unfortunately, the Readability Statistics dialog box doesn’t tell you the lengths of your sentences, but it’s easy enough to get a VBA macro to do it for you, as shown in Listing 1.
Listing 1 A Macro That Displays the Lengths of Sentences in the Active Document
Using the ActiveDocument object, the macro makes a first pass through all the sentences to find the one with the most words. The macro then uses this maximum word count to rediÂmension the sentenceLengths array, which is used to hold the number of occurrences of each sentence length within the document. To calculate these frequencies, the macro then runs through all the sentences again and increments the array values for each length. The macro finishes by constructing and then displaying a string that holds the sentence lengths and frequencies. Figure 1 shows an example.

Figure 1 The Display-SentenceLengths macro displays a mesÂsage box such as this to show you the document’s sentence lengths and the frequency with which each length occurs.
TIP
If you’re also interested in displaying data for each paragraph, replace .Sentencesin Listing 1.1 with .Paragraphs. Because the variable sis a Rangeobject, you can work with either the words in each paragraph-s.Words.Count-or the sentences in each paragraph-s.Sentences.Count.
Technorati Tags: sentence word counts
Popularity: 2% [?]









Recent Comments