|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim s$, n%, i%, arr, doc As Object, fso As Object, fp As Object, f As Object
- Dim Regx As Object, mh As Object
- Set Regx = CreateObject("vbscript.regexp")
- Regx.Pattern = ".班费用(\d{1,5})万元"
- Regx.Global = True
- Set fso = CreateObject("scripting.filesystemobject")
- Set fp = fso.getfolder(ThisWorkbook.Path)
- ReDim arr(1 To 3, 1 To 13)
- For Each f In fp.Files
- If f Like "*.doc*" Then
- Set doc = GetObject(f)
- s = doc.Content
- Set doc = Nothing
- Set mh = Regx.Execute(s)
- If mh.Count <> 0 Then
- For i = 0 To mh.Count - 1
- arr(1, i + 1) = mh(i).submatches(0)
- arr(2, i + 1) = "万元"
- arr(3, i + 1) = mh(i)
- Next
- End If
- End If
- Next
- Set Regx = Nothing: Set fp = Nothing
- Set fso = Nothing
- Sheets("Sheet1").Range("a7").Resize(UBound(arr, 2), UBound(arr, 1)) = WorksheetFunction.Transpose(arr)
- End Sub
复制代码 |
|