|
- Sub 提取二级标题的内容()
- Dim br(1 To 100, 1 To 3)
- With CreateObject("shell.application")
- Set my = .browseforfolder(0, "getfolder", 0, 0)
- If Not my Is Nothing Then mypath = my.self.Path Else Exit Sub
- End With
- With CreateObject("wscript.shell")
- ar = Split(.exec("cmd /c dir /a-d /b " & Chr(34) & mypath & Chr(34)).stdout.readall, vbCrLf)
- ar = Filter(ar, "doc")
- For q = 0 To UBound(ar)
- Set doc = GetObject(mypath & "" & ar(q))
- s = s & doc.Range.Text
- doc.Close
- Next
- End With
- For i = 8 To 13
- s = Replace(s, Chr(i), "") & "标题"
- Next
-
- With CreateObject("vbscript.regexp")
- .Global = True
- .Pattern = "(\d{4})([\s\S]+?)标题"
- Set mat = .Execute(s)
- For i = 0 To mat.Count - 1
- n = n + 1
- br(n, 1) = "标题" & Left(mat(i).submatches(0), 2)
- br(n, 2) = "标题" & mat(i).submatches(0)
- br(n, 3) = mat(i).submatches(1)
- Next
- End With
- [a3].Resize(n, 3) = ""
- [a3].Resize(n, 3) = br
- End Sub
复制代码 |
|