是否有内置的功能可以计算ms-excel-2010中使用的单词数?
更具体地讲,在选定范围内的字数是多少?
目前,我将范围复制到ms-word中以获取使用的单词数。
笔记。我对字符数等不感兴趣,仅对字数不感兴趣。
经过对论坛的深入研究,我发现下面的代码与我正在寻找的代码非常接近:
Sub CountWords()
Dim MyRange As Range
Dim CellCount As Long
Dim TotalWords As Long
Dim NumWords As Integer
Dim Raw As String
'ACTIVE SELECTION
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句