locked
Flesch-Kincaid Readability Scoring code RRS feed

  • Question

  • I am trying to come up with the VBA code to be able to review an article of a few thousand words (3,00-7,000 words) and output a score based on the following equation;

    (Total Words/Total sentences)-(Total Syllables/Total Words)

    Ideally the score would come from then looking at this table and delivering the School Level.

    Score School level Notes
    100.00–90.00 5th grade Very easy to read. Easily understood by an average 11-year-old student.
    90.0–80.0 6th grade Easy to read. Conversational English for consumers.
    80.0–70.0 7th grade Fairly easy to read.
    70.0–60.0 8th & 9th grade Plain English. Easily understood by 13- to 15-year-old students.
    60.0–50.0 10th to 12th grade Fairly difficult to read.
    50.0–30.0 College Difficult to read.
    30.0–10.0 College graduate Very difficult to read. Best understood by university graduates.
    10.0–0.0 Professional Extremely difficult to read. Best understood by university graduates.

    Any ideas?

    Saturday, September 26, 2020 11:43 PM

Answers

  • On the back of comments from NLtL and mogulman52 (I wouldn't I have known) it seems it is possible to return the statistics with VBA (after completing the spell check)

    Sub test()
    Dim rng As Word.Range
    Dim stat As ReadabilityStatistic
    
        Set rng = ActiveDocument.Content
    
        For Each stat In rng.ReadabilityStatistics
            Debug.Print stat.Name, stat.Value
        Next
    
        Set stat = rng.ReadabilityStatistics("Flesch Reading Ease")
    
        MsgBox stat.Name & ": " & stat.Value & vbNewLine & LookupGrade(stat.Value)
    
    End Sub
    
    Function LookupGrade(grade As Single) As String
    Dim s As String
        Select Case grade
        Case Is >= 90: s = "5th grade"
        Case Is >= 80: s = "6th grade"
        Case Is >= 70: s = "7th grade"
        Case Is >= 60: s = "8th and 9th grade"
        Case Is >= 50: s = "10th to 12th grade"
        Case Is >= 30: s = "College"
        Case Is >= 10: s = "College graduate"
        Case Else: s = "Professional"
        End Select
    
        LookupGrade = "School Level: " & s
    End Function

    Sunday, September 27, 2020 4:46 PM

All replies

  • If the article is a Word doc then Word provides a score. Click File>Options>Proofing.  Check the box labeled "Show readability statistics" in the "When correcting spelling and grammar in Word" section.  Click OK.  Now click the Review tab and click "Spelling and Grammar".  After all mistakes are corrected, you'll see the statistics.

    As far as I know there no way to get score in VBA.  Also, the doc can't have any spelling errors to get score.

    Sunday, September 27, 2020 2:29 PM
  • On the back of comments from NLtL and mogulman52 (I wouldn't I have known) it seems it is possible to return the statistics with VBA (after completing the spell check)

    Sub test()
    Dim rng As Word.Range
    Dim stat As ReadabilityStatistic
    
        Set rng = ActiveDocument.Content
    
        For Each stat In rng.ReadabilityStatistics
            Debug.Print stat.Name, stat.Value
        Next
    
        Set stat = rng.ReadabilityStatistics("Flesch Reading Ease")
    
        MsgBox stat.Name & ": " & stat.Value & vbNewLine & LookupGrade(stat.Value)
    
    End Sub
    
    Function LookupGrade(grade As Single) As String
    Dim s As String
        Select Case grade
        Case Is >= 90: s = "5th grade"
        Case Is >= 80: s = "6th grade"
        Case Is >= 70: s = "7th grade"
        Case Is >= 60: s = "8th and 9th grade"
        Case Is >= 50: s = "10th to 12th grade"
        Case Is >= 30: s = "College"
        Case Is >= 10: s = "College graduate"
        Case Else: s = "Professional"
        End Select
    
        LookupGrade = "School Level: " & s
    End Function

    Sunday, September 27, 2020 4:46 PM
  • I will have to see if this works on my PC if I ever get it fixed. In the meantime, I'm using Office 365 and a Mac. The path File>Options, etc doesn't work because there is no Options. I've looked around to see if the statistics were available under a different heading, but couldn't find it anywhere. It would have been a great resolution. Thanks for the response.
    Sunday, September 27, 2020 7:26 PM