|
本帖最后由 duquancai 于 2016-10-24 12:30 编辑
- Sub WordVBA()
- Dim mt, oRang As Range, rng As Range, S$
- Dim arr(1 To 1000, 1 To 4)
- Set rng = ActiveDocument.Content
- Application.ScreenUpdating = False
- ActiveDocument.Content.ListFormat.ConvertNumbersToText
- With CreateObject("vbscript.regexp")
- .Pattern = "(\d{4})年工程((?:(?!\d{4}年工程)[\s\S])*)"
- .Global = True: .MultiLine = True
- For Each mt In .Execute(rng)
- .Pattern = "^(\d+)\..*?^项目:\s*([^\r]+)\r完成时间:\s*([^\r]+)"
- S = mt.submatches(1): t = mt.submatches(0)
- For Each mh In .Execute(S)
- n = n + 1
- arr(n, 1) = t
- arr(n, 2) = mh.submatches(0)
- arr(n, 3) = mh.submatches(1)
- arr(n, 4) = "'" & mh.submatches(2)
- Next
- Next
- End With
- With CreateObject("Excel.Application")
- If Tasks.Exists("Microsoft Excel") = True Then Tasks("Microsoft Excel").Close
- Set myBook = .Workbooks.Add: .Visible = True
- Set mysheet = myBook.Worksheets("sheet1"): mysheet.Activate
- mysheet.Range("a1:d1") = Array("年份", "序号", "项目", "完成时间")
- mysheet.Range("a2").Resize(n, 4) = arr
- End With
- Set myBook = Nothing: Set mysheet = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|