本帖最后由 weiyingde 于 2017-5-25 18:49 编辑
Sub 将文档中以数字开头的段落依次录入数组()
Dim arr(), m
With ActiveDocument.Content
.Find.Execute "^w", , , , , , , , , "^32", 2
.Find.Execute "([!A-Za-z])(^32)([!A-Za-z])", , , 1, , , , , , "\1\3", 2
.Find.Execute "([A-Za-z])(^32)([!A-Za-z])", , , 1, , , , , , "\1\3", 2
.Find.Execute "([!A-Za-z])(^32)([A-Za-z])", , , 1, , , , , , "\1\3", 2
.Find.Execute "^11", , , 1, , , , , , "^p", 2 '
.Find.Execute "(^32{1,})(*)(^13)", , , 1, , , , , , "\2\3", 2
.Find.Execute "(*)(^13)(^32{1,})", , , 1, , , , , , "\1\2", 2
End With
Set sr = ActiveDocument.Content
With CreateObject("vbscript.regexp")
.Global = True
.IgnoreCase = False
.MultiLine = True
.Pattern = "[\d]{1,}.*^13"
For Each m In .Execute(sr)
n = n + 1
ReDim Preserve arr(1 To n)
arr(n) = m.Value
Next
For i = LBound(arr) To UBound(arr)
MsgBox arr(i)
Next
End With
End Sub |