我需要關於如何統計Excel中文本中「和號」和感嘆號的數量的幫助。我只能得到第一行,但值不更新。這是我迄今爲止的代碼。謝謝。在Excel中按行計算「與號」和「感嘆號」的行數
Sub Display_Readability_Scores()
Dim Stats As Variant
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 ActiveDocument As Object
Dim row As Integer
Dim column As Integer
Dim amp As String
row = 2
Set ActiveDocument = CreateObject("Word.Document")
Do While Worksheets("Sheet1").Cells(row, 1) <> ""
ActiveDocument.Content = Worksheets("Sheet1").Cells(row, 2)
column = 3
Words = ActiveDocument.Content.ReadabilityStatistics(1).Value
Characters = ActiveDocument.Content.ReadabilityStatistics(2).Value
Paragraphs = ActiveDocument.Content.ReadabilityStatistics(3).Value
Sentences = ActiveDocument.Content.ReadabilityStatistics(4).Value
Sentences_per_paragraph = ActiveDocument.Content.ReadabilityStatistics(5).Value
Words_per_sentence = ActiveDocument.Content.ReadabilityStatistics(6).Value
Characters_per_word = ActiveDocument.Content.ReadabilityStatistics(7).Value
Ratio_of_passive_sentences = ActiveDocument.Content.ReadabilityStatistics(8).Value
Flesch_Reading_Ease_score = ActiveDocument.Content.ReadabilityStatistics(9).Value
Flesch_Kincaid_Grade_Level_score = ActiveDocument.Content.ReadabilityStatistics(10).Value
amp = Application.WorksheetFunction.CountIf("Worksheets("Sheet1").Cells(row, 2), "&")
For Each Stats In Worksheets("Sheet1").Cells(row, 2)
Worksheets("Sheet1").Cells(row, column) = Words
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Characters
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Paragraphs
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Sentences
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Sentences_per_paragraph
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Words_per_sentence
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Characters_per_word
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Ratio_of_passive_sentences
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Flesch_Reading_Ease_score
column = column + 1
Worksheets("Sheet1").Cells(row, column) = Flesch_Kincaid_Grade_Level_score
column = column + 1
Worksheets("Sheet1").Cells(row, column) = amp
row = row + 1
Next Stats
Loop
End Sub
你確定這是有關到Excel - 不字? – 2013-02-21 19:15:08
此線具有一個錯誤的引用: 安培= Application.WorksheetFunction.CountIf( 「工作表(」 工作表Sheet「 。)細胞(行,2), 」&「) 應 安培= application.worksheetfunction.countif (工作表(「sheet1」)。cells(row,2),「&」),但我猜這是一個複製問題,因爲excel應該立即打破在這種情況下 – scott 2013-02-21 19:16:56
@PeterL .:我的錯誤。因爲我不清楚Excel或Word或兩者是否都涉及 – bernie 2013-02-21 19:17:29