|
可试试如下代码(仅针对附件文档):- Sub test()
- Dim i%, j%, n%, d, temp, data$(), info$()
- Dim myDoc As Document, newDoc As Document
-
- Set d = CreateObject("Scripting.dictionary")
- Application.ScreenUpdating = False
- Set myDoc = ActiveDocument
- With myDoc.Content.Find
- .Style = "标题"
- Do While .Execute
- ReDim Preserve data(5, i)
- temp = Split(.Parent.Next(4, 2).Text, ":")
- data(0, i) = i + 1
- data(1, i) = Replace(.Parent.Text, Chr(13), "")
- data(2, i) = Replace(temp(1), "标准编号", "")
- data(3, i) = Replace(temp(2), Chr(13), "")
- data(4, i) = .Parent.Information(3)
- j = InStrRev(data(2, i), "-")
- data(5, i) = Left(data(2, i), j) & Format(Mid(data(2, i), j + 1), "000")
- If d.Exists(data(3, i)) = False Then
- d(data(3, i)) = d(data(3, i)) + 1
- Else
- ReDim Preserve info(n)
- info(n) = n + 1 & Chr(9) & data(3, i) & Chr(9) _
- & data(1, i) & Chr(9) & data(2, i) & Chr(9) & data(4, i)
- n = n + 1
- End If
- i = i + 1
- Loop
- End With
- WordBasic.sortarray data, 0, 0, i - 1, 1, 5
- Set newDoc = Documents.Add(myDoc.FullName)
- newDoc.Content.Delete
- With myDoc
- For i = 0 To UBound(data, 2)
- .GoTo(1, 1, data(4, i)).Select
- Do While Selection.Style <> "标题"
- Selection.MoveDown 4
- Loop
- newDoc.Bookmarks("\endofdoc").Range.FormattedText = .Bookmarks("\headinglevel").Range.FormattedText
- Next
- End With
- With newDoc.Content
- .Parent.Styles("标题").ParagraphFormat.PageBreakBefore = True
- .Find.Execute findtext:="^m", replacewith:="", Replace:=2
- If n > 0 Then .InsertAfter Chr(13) & "重复的标准编号:" & Chr(13) & Join(info, Chr(13))
- End With
- ReDim info(i - 1)
- For i = 0 To UBound(data, 2)
- info(i) = info(i) & i + 1 & vbTab & data(1, i) & Chr(9) & data(2, i) & Chr(9) _
- & data(3, i) & Chr(9) & data(4, i)
- Next i
- With Documents.Add.Content.ParagraphFormat
- .Parent.Text = "查找结果" & Chr(13) & Join(info, Chr(13))
- .TabStops.Add 40
- .TabStops.Add 190
- .TabStops.Add 260
- .TabStops.Add 400
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|