|
本帖最后由 wx486 于 2013-8-12 18:28 编辑
excelzfsn 发表于 2013-8-12 16:15
请测试。
桌面.zip
(32.94 KB, 下载次数: 319)
- Sub test111()
- Dim mat, arr, i%, j%, ex As Object, wb
- With CreateObject("vbscript.regexp")
- .Global = True
- .Pattern = "[\d\.]+(?=万元)"
- ActiveDocument.Content = .Replace(ActiveDocument.Content, " ")
- .Pattern = ".(?=万元)"
- Set mat = .Execute(ActiveDocument.Content)
- End With
- ReDim arr(1 To mat.Count)
- Set ex = CreateObject("excel.application")
- Set wb = ex.workbooks.Open(ActiveDocument.Path & "\液处理站工程.xls")
- With wb
- arr(1) = .sheets(2).[c28]
- arr(2) = .sheets(2).[c5]
- arr(3) = .sheets(2).[c15]
- arr(4) = .sheets(2).[c26]
- arr(5) = .sheets(3).[c15]
- arr(6) = .sheets(2).[c29]
- arr(7) = .sheets(3).[c8]
- arr(8) = .sheets(3).[c12]
- For i = 9 To 12
- arr(i) = .sheets(1).Cells(i - 2, "r")
- Next
- arr(13) = .sheets(1).[r17]
- arr(14) = .sheets(1).[r18]
- arr(15) = .sheets(1).[r21]
- arr(16) = 1.5
- arr(17) = .sheets(1).[r22]
- .Close False
- End With
- ex.Quit
- Set ex = Nothing
- With ActiveDocument.Content.Find
- .Text = " 万元"
- Do While .Execute
- j = j + 1
- .Parent = arr(j) & "万元"
- .Parent.Collapse wdCollapseEnd
- Loop
- End With
- MsgBox "OK"
- End Sub
复制代码
|
|