如何计算 Microsoft Excel 文件中的单词数?

如何计算 Microsoft Excel 文件中的单词数?

我需要计算一个单词的总数量微软 Excel文件。通常,在 MS Word 或 PowerPoint 中,它显示在状态栏或属性窗口中。但在 Excel 中,它不在任何地方显示。

有解决办法吗?

答案1

您可以为此创建一个宏:

按 ALT + F11 并输入以下代码。

然后选择整个工作表并运行宏进行字数统计。您也可以只选择一个部分并只对该部分进行字数统计。

Sub CountWords()
Dim MyRange As Range
Dim CellCount As Long
Dim TotalWords As Long
Dim NumWords As Integer
Dim Raw As String

Set MyRange = ActiveSheet.Range(ActiveWindow.Selection.Address)
TotalWords = 0
For CellCount = 1 To MyRange.Cells.Count
If Not MyRange.Cells(CellCount).HasFormula Then
Raw = MyRange.Cells(CellCount).Value
Raw = Trim(Raw)
If Len(Raw) > 0 Then
NumWords = 1
Else
NumWords = 0
End If
While InStr(Raw, " ") > 0
Raw = Mid(Raw, InStr(Raw, " "))
Raw = Trim(Raw)
NumWords = NumWords + 1
Wend
TotalWords = TotalWords + NumWords
End If
Next CellCount
MsgBox "There are " & TotalWords & " words in the selection."
End Sub

答案2

尝试如下公式:

=LEN(A3)-LEN(SUBSTITUTE(A3," ",""))+1

截屏

相关内容