|
sylun 发表于 2012-6-13 18:16
是不很准确,主要原因是文档有语法和拼写错误时可能会导致遍历Words集合对象成员时重复计算,为何会这样还 ...
谢谢您的关注和修改,经测试代码统计结果还是不准确。以下版主的代码最为准确,但有些词组会统计不到:
Sub UniqWordsCount()
'很准确
'直接输出到新文档
Dim aword As Range
Dim aString As String, cstring As String
aString = ChineseFont(ThisDocument.Range.Text, True)
'净化处理一下
'Debug.Print aString
For Each aword In ThisDocument.Words
If ChineseFont(aword, True) <> "" Then
' If aword <> " " And VBA.Asc(aword) <> 13 Then
If InStr(1, cstring, aword & ":" & Chr(9)) Then
'如果累积生成的字串cstring中已经存在,则什么也不做,避免重复
Else
arr = Split(aString, aword)
cstring = cstring & aword & ":" & Chr(9) & UBound(arr) & Chr(13)
End If
End If
Next
Documents.Add
Selection.InsertBefore cstring
End Sub |
|