|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
今天用字典+excel排序做了个word词频统计程序,没想到速度这么快。
Sub word词频排序()
'首先请引用excel11,我的是office2003
Application.ScreenUpdating = False
Dim dic As Object
Dim i, s
Dim f()
Dim m()
Set dic = CreateObject("scripting.dictionary")
For Each i In ActiveDocument.Words
s = CStr(i)
If i <> Chr(13) Then
If dic.Exists(s) Then
dic.Item(s) = dic.Item(s) + 1
Else
dic.Add (s), 1
End If
End If
Next
f = dic.keys
m = dic.items
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
With xlSheet
[a2].Resize(dic.Count, 1) = xlBook.Application.Transpose(f)
[b2].Resize(dic.Count, 1) = xlBook.Application.Transpose(m)
[a1].Resize(1, 2) = Array("词条名称 ", "找到个数")
Range("B2:B" & dic.Count).Select
Range("A2:B" & dic.Count).Sort Key1:=Range("B2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal
End With
Application.ScreenUpdating = True
End Sub |
评分
-
1
查看全部评分
-
|