|
楼主 |
发表于 2019-7-1 20:34
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 拆句成词()
Dim s$, b(), n, t As Boolean
For k = 1 To ActiveDocument.Paragraphs.Count
s = ActiveDocument.Paragraphs(k).Range
If Len(s) < 2 Then
Else
With CreateObject("vbscript.regexp")
.Pattern = "[^\w ]+"
.Global = True
a = Split(.Replace(LCase(s), ""), " ")
ReDim b(UBound(a), 1)
For i = 0 To UBound(a)
b(i, 0) = Rnd(): b(i, 1) = a(i)
Next
For i = 0 To UBound(b) - 1
n = b(i, 0)
For j = i + 1 To UBound(b)
If n > b(j, 0) Then n = b(j, 0): jj = j: t = True
Next
If t Then
t = False
For j = 0 To 1
n = b(i, j): b(i, j) = b(jj, j): b(jj, j) = n
Next
End If
Next
For i = 0 To UBound(a)
a(i) = b(i, 1) & " "
Next
ActiveDocument.Paragraphs(k).Range.Text = ""
Set oRng = ActiveDocument.Range(ActiveDocument.Paragraphs(k).Range.Start, ActiveDocument.Paragraphs(k).Range.Start)
oRng.Text = Join(a, ",") & Chr(13)
End With
End If
Next
End Sub
以上是我手头的拆解代码,但还不够完善。 |
|