|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
楼主,下面是本坛大神 杜先生/老师 的代码,请把前 5 行放到 Option Explict 下面,Sub 前面,然后执行 main 宏(杜先生 想删除,可没那么容易,我幸好保留着):
- Private Declare Function hash Lib "ntdll.dll" Alias "RtlComputeCrc32" (ByVal start As Long, ByVal data As Long, ByVal Size As Long) As Long
- Private Hash_Table() As Long
- Private Count_Table As Long
- Private H As Long
- Public Count As Long
- Sub main()
- Dim mts As Object, mt As Object, reg As Object, keys$()
- Dim myStr As String, n As Long, nDoc As Document, rStr As String
- myStr = ActiveDocument.Content.Text
- Set reg = CreateObject("vbscript.regexp")
- reg.Global = True: reg.Pattern = "[^\sx0bx0cx0exa0x02\u3000]"
- Set mts = reg.Execute(myStr)
- Call Init(mts.Count): ReDim keys(1 To mts.Count)
- For Each mt In mts
- Call Add(mt.Value, keys)
- Next
- For n = 1 To Count
- rStr = rStr & keys(n)
- Next
- Set nDoc = Documents.Add
- nDoc.Content.Text = rStr
- End Sub
- Public Sub Init(bCount&)
- Count = 0
- Count_Table = bCount * 1.33
- ReDim Hash_Table(Count_Table - 1)
- End Sub
- Public Function Add(Key, keys) As Boolean
- Dim k&
- H = (hash(0, StrPtr(Key), LenB(Key)) And &H7FFFFFFF) Mod Count_Table
- Do
- If Hash_Table(H) = 0 Then
- Count = Count + 1
- Hash_Table(H) = Count
- keys(Hash_Table(H)) = Key
- Add = True
- Exit Function
- End If
- If StrComp(Key, keys(Hash_Table(H))) = 0 Then Exit Function
- k = k + 1
- H = (H + k * k) Mod Count_Table
- Loop
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|