|
本帖最后由 413191246se 于 2019-8-22 21:38 编辑
* 楼主,我觉得繁体字和简体字统计字频应该是一样的,请做一个小型示例文档,检测试用一下我编的宏:(如果正式应用于大型文档,可能运行时间较长,请耐心等待,不要动键盘和鼠标。如果不满意,请等待高人援手)- Sub test字频统计()
- Dim i&, j&, t$, n&, s$, x&
- With ActiveDocument
- x = .Paragraphs.Count
- j = .Characters.Count
- For i = 1 To j
- t = .Characters(i)
- If t = vbCr Then GoTo sk
- If t = ChrW(160) Then GoTo sk
- If t = vbTab Then GoTo sk
- If t Like "[,;:、。“!?” ]" Then GoTo sk
- If .Characters(i).Font.Color = wdColorRed Then GoTo sk
- With .Content.Find
- .ClearFormatting
- .Text = t
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- n = n + 1
- .Font.Color = wdColorRed
- .Start = .End
- End With
- Loop
- End With
- s = s & t & " " & n & vbTab
- n = 0
- sk:
- Next i
- End With
- Selection.EndKey 6
- Selection.TypeText Text:=vbCr & s
- '''
- With ActiveDocument
- .Paragraphs.Last.Range.Find.Execute "^9", , , , , , , , , "^p", 2
- .Paragraphs.Last.Range.Delete
- .Range(Start:=ActiveDocument.Paragraphs(x + 1).Range.Start, End:=ActiveDocument.Content.End).Select
- End With
- '
- With Selection
- .ConvertToTable Separator:=4, NumColumns:=2, AutoFitBehavior:=wdAutoFitFixed
- .Tables(1).Style = "网格型"
- '
- .Sort ExcludeHeader:=False, FieldNumber:="列 2", SortFieldType:= _
- wdSortFieldNumeric, SortOrder:=wdSortOrderDescending, FieldNumber2:="", _
- SortFieldType2:=wdSortFieldSyllable, SortOrder2:=wdSortOrderAscending, _
- FieldNumber3:="", SortFieldType3:=wdSortFieldSyllable, SortOrder3:= _
- wdSortOrderAscending, Separator:=wdSortSeparateByCommas, SortColumn:= _
- False, CaseSensitive:=False, LanguageID:=wdSimplifiedChinese, _
- SubFieldNumber:="段落数", SubFieldNumber2:="段落数", SubFieldNumber3:="段落数"
- End With
- MsgBox "处理完毕!!!!!!!!!!", 0 + 48, "字频统计"
- End Sub
复制代码
|
|