由于小孩读经,无法统计背诵量,在网上找了一段统计汉字的代码。略作修改,解决word统计汉字总量的不准确的问题,同时原作者解决了不重复汉字的统计的问题。感谢作者。此处志存!
Sub 统计重复与不重复汉字()
Dim AllText
As String, B As String
Dim i As
Long, StartTime As Single
Dim j As
Long
Dim OnlyText
As String
Dim
ResultStr As String
StartTime =
Timer
j = 0
'所有字符统计变量初始化
AllText =
ActiveDocument.Content.Text
For i = 1 To
Len(AllText)
B = Mid(AllText, i, 1)
If B Like "[一-龥]" Then '如果属于汉字字符(CJK统一汉字字符集)
j = j + 1 '统计总的字符数,word自己统计有问题
If OnlyText = "" Then
OnlyText = B '为变量赋初值
ElseIf VBA.InStr(OnlyText, B) = 0 Then
'如果在OnlyText变量中,没有出现过的字符,则加入该变量字符集中,牛,这个InStr函数很有用
OnlyText = OnlyText & B
End If
End If
Next
ResultStr =
"不重复汉字数/汉字总数:" & Str(Len(OnlyText))
& "/" & Trim(Str(j))
MsgBox
ResultStr, vbOKOnly, "汉字统计"
End Sub
加载中,请稍候......