![如何计算 Microsoft Excel 文件中的单词数?](https://linux22.com/image/1550120/%E5%A6%82%E4%BD%95%E8%AE%A1%E7%AE%97%20Microsoft%20Excel%20%E6%96%87%E4%BB%B6%E4%B8%AD%E7%9A%84%E5%8D%95%E8%AF%8D%E6%95%B0%EF%BC%9F.png)
我需要计算一个单词的总数量微软 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