MS Excel 2010中的字数统计

彼得·H

是否有内置的功能可以计算使用的单词数

更具体地讲,在选定范围内的字数是多少?

目前,我将范围复制到以获取使用的单词数。

在此处输入图片说明

笔记。我对字符数等不感兴趣,仅对字数不感兴趣。

彼得·H

经过对论坛的深入研究,我发现下面的代码与我正在寻找的代码非常接近:

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章