Updated News Around the World

How to use VBA procedures for quick access to readability statistics in Word

If you need to frequently refer to readability statistics in Microsoft Word, but you dread running through spell check unnecessarily, these macros are for you!

Typing on laptop

Image: iStock/Aleksei Morozov

Many of us depend on readability statistics to improve our writing or to write to a specific audience in Microsoft Word. If the feature is enabled, you’ll see a list of statistics after running spell check. Unfortunately, running spell check is the only time you’ll see those statistics, which can be tedious especially if the document is large and complex. If you cancel the spell check, you won’t see the statistics. In this article, I’ll show you a few VBA procedures that will display statistics in three different ways.

SEE: 69 Excel tips every user should master (TechRepublic)

I’m using Microsoft 365 on a Windows 10 64-bit system, but you can use earlier versions. The online version doesn’t support macros. You can download the demonstration .docx, .doc and .cls files or use the =RAND() function to create a few paragraphs of text and enter the code yourself. This article assumes you have basic Word skills, but even a beginner should be able to work through this article with success.

How to enable readability statistics in Microsoft Word

If you don’t see readability statistics after running spell check, the feature isn’t enabled. To enable it, do the following:

  1. Click the File tab and choose Options (or More if Options isn’t visible).
  2. Choose Proofing in the left pane.
  3. In the When Correcting Spelling and Grammar in Word section, check the Show Readability Statistics option, as shown in Figure A.

Figure A

wordvbareadability-a2.jpg

How to enable readability statistics.

How to enter and run code in Word

To enter code, press Alt + F11 to open the Visual Basic Monitor. In the Project Explorer to the left, choose ThisWorkbook and enter the code. Or import the downloadable .cls file. Don’t paste code directly from this web page. Instead, you can copy it to any text editor and then copy the text from the text editor into a module. If you’re using a ribbon version, you must save the file as a macro-enabled file to use macros.

SEE: Windows 10: Lists of vocal commands for speech recognition and dictation (free PDF) (TechRepublic)

When in the VBE, you can press F5 to run a procedure, but be sure to click inside the procedure you want to run. When in a Word document, click the Developer tab, click Macros in the Code group, choose the procedure in the resulting dialog shown in Figure B, and then click Run.

Figure B

wordvbareadability-a.jpg

  How to run a procedure from the Developer tab.

How to display the readability statistics one by one

The only way to trigger Word’s readability statistics via the interface is to run a spell check (F7). If your document is long, you can waste a bit of time trying to work through the document. If you cancel the spell check, Word returns you to the document immediately, without displaying the statistics.

The short procedure in Listing A will display all the statistics, one by one. It’s a bit tedious if you only want to view one of them, but you can run this outside of a spell check task.

Listing A

Sub Readability()

‘Cycle through the readability statistics and display one by one in a message box.

For Each rs In Selection.Range.ReadabilityStatistics

    MsgBox rs.Name & ” – ” & rs.Value

Next rs

End Sub

Run the macro, and you’ll see a message box similar to the one in Figure C. You must press OK to view the next statistic—there are several of them.

Figure C

wordvbareadability-b.jpg

  Press OK to view more statistics.

The For Each loop cycles through the ReadabilityStatistics collection. The message box displays the concatenated Name and Value properties in the following order: Words, Characters, Paragraphs, Sentences, Sentences per Paragraph, Words per Sentence, Characters per Word, Passive Sentences, Flesch Reading Ease, Flesch-Kincaid Grade Level and Passive Sentences. You can’t change the order in this simple procedure. To view specific statistics, add a check for that object.

How to display the readability statistics one at a time

Cycling through all of the statistics one by one is OK, but perhaps you want to see only one statistic. In this case, you can specify that statistic object as shown in Listing B. This procedure displays only one statistic, the Flesch-Kincaid Grade Level, whose index value is 9. (More about that in a minute.) Figure D shows the result of running this procedure.

Listing B

Sub ReadabilityGradeLevel()

‘Display grade level.

Set rsRange = ActiveDocument.Content

rs = rsRange.ReadabilityStatistics(9).Value

MsgBox “Grade Level: ” & rs

End Sub

Figure D

wordvbareadability-c.jpg

  You can display only one statistic.

You might have noticed that this procedure uses the index value 9 to retrieve the grade-level statistic. Remember the order I mentioned, and that you can’t change it? That’s where the index values come in. See Table A for a complete list. Use index values to display specific statistic values.

Table A

Words

0

Characters

1

Paragraphs

2

Sentences

3

Sentences per Paragraph

4

Words per Sentence

5

Characters per Word

6

Passive Sentences

7

Flesch Reading Ease

8

Flesch-Kincaid Grade Level

9

Passive Sentences

10

So far, we’ve seen two procedures that return readability statistics: one displays them all one at a time, and one displays only one. Let’s look at a procedure that displays them all at the same time.

How to display the readability statistics all at once

It’s likely that you’ll want to see all of the statistics in one efficient screen. Listing C does this. It’s basically the same as Listing A, but this time, the code creates a long string that contains all of the statistics and displays that string in one message box screen, as shown in Figure E.

Listing C

Sub ReadabilityOneScreen()

‘Display all readability statistics on one screen.

Dim strStats As String

‘Reset string to nothing.

strStats = “”

‘Cycle through statistics and build string.

For Each rs In Selection.Range.ReadabilityStatistics

    strStats = strStats & rs.Name & “: ” & rs.Value

    strStats = strStats & vbCrLf

Next rs

‘Display all stats.

MsgBox strStats, vbOKOnly, “Readability Statistics”

End Sub

Figure E

wordvbareadability-d.jpg

  You can display all statistics at the same time. 

You can display them all at once!

As is, none of the procedures contain any error handling, so you might want to drop in some code to cover potential errors. If you use these statistics, outside of spell check, often, you might want to add a custom group to the ribbon and add the appropriate statistic-displaying macros there. 

Also see

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! NewsUpdate is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – [email protected]. The content will be deleted within 24 hours.