|
利用正则对象及字典对word文档进行排序
文档中包含“嵌入式”图片、表格及文字对象,详见附件
- Sub 排序()
- Dim mt, oRng As Range, n&, m&, str$, Unm, k()
- Dim d, Ydoc As Document, Mdoc As Document
- Set Ydoc = ThisDocument
- Set d = CreateObject("Scripting.Dictionary")
- Set reg = CreateObject("vbscript.regexp")
- reg.Global = True: reg.IgnoreCase = False: reg.MultiLine = True
- reg.Pattern = "^[((]\s*(\d+)\s*[))](?:(?!^[((]\s*\d+\s*[))]).)+"
- str = Replace(Ydoc.Content, Chr(7), "")
- For Each mt In reg.Execute(str)
- Unm = mt.submatches(0)
- m = mt.FirstIndex: n = mt.Length
- Set oRng = Ydoc.Range(m, m + n)
- Set d(Unm) = oRng
- Next
- k = d.keys: WordBasic.SortArray k()
- Set Mdoc = Documents.Add
- For i = 0 To d.Count - 1
- With Mdoc.Content
- .Collapse 0
- .FormattedText = d(CStr(k(i))).FormattedText
- End With
- Next
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|