是否可以从 excel 中的超链接读取网页并直接计算网页的可读性分数、与号和感叹号,而无需通过更改此 VBA 代码将数据查询回 excel?也有可能来自文件路径?这一切都在一个电子表格中。
Option Compare Text
Sub Display_Stylometric_Scores()
Dim Words As String
Dim Characters As String
Dim Paragraphs As String
Dim Sentences As String
Dim Sentences_per_paragraph As String
Dim Words_per_sentence As String
Dim Characters_per_word As String
Dim Ratio_of_passive_sentences As String
Dim Flesch_Reading_Ease_score As String
Dim Flesch_Kincaid_Grade_Level_score As String
Dim Coleman_Liau_Readability_Score As String
Dim Ampersands As Long
Dim Exclamations As Long
Dim row As Integer
Dim column As Integer
Dim ActiveDocument As Object
Dim RS As Object
Dim txt As String
row = 3
Set ActiveDocument = CreateObject("Word.Document")
Do While Worksheets("Sample_Output_2").Cells(row, 1) <> ""
txt = Worksheets("Sample_Output_2").Cells(row, 2).Value
ActiveDocument.Content = txt
Set RS = ActiveDocument.Content.ReadabilityStatistics
Words = RS(1).Value
Characters = RS(2).Value
Paragraphs = RS(3).Value
Sentences = RS(4).Value
Sentences_per_paragraph = RS(5).Value
Words_per_sentence = RS(6).Value
Characters_per_word = RS(7).Value
Ratio_of_passive_sentences = RS(8).Value
Flesch_Reading_Ease_score = RS(9).Value
Flesch_Kincaid_Grade_Level_score = RS(10).Value
Ampersands = CountChar(txt, "&")
Exclamations = CountChar(txt, "!")
Worksheets("Sample_Output_2").Cells(row, 4).Resize(1, 12).Value =
Array(Words, Characters, Paragraphs, Sentences, Sentences_per_paragraph, _
Words_per_sentence, Characters_per_word, Ratio_of_passive_sentences, _
Flesch_Reading_Ease_score, Flesch_Kincaid_Grade_Level_score, _
Ampersands, Exclamations)
row = row + 1
Loop
End Sub
Function CountChar(txt As String, char As String) As Long
CountChar = Len(txt) - Len(Replace(txt, char, ""))
End Function