|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim wordapp As Object
- Dim mydoc As Object
- Dim reg As Object
- Dim i%, r%
- Dim brr(1 To 2000, 1 To 9)
- Set wordapp = CreateObject("word.application")
- Set reg = CreateObject("vbscript.regexp")
- With reg
- .Global = True
- .MultiLine = True
- .Pattern = "[A-Z]、.*?(?:\s*\x0A|\x0D|\x20)"
- End With
- Set mydoc = wordapp.Documents.Open(ThisWorkbook.Path & "" & "请教.doc")
- With mydoc
- .Range.ListFormat.ConvertNumbersToText
- arr = Split(.Range.Text, vbCr)
- End With
- mydoc.Close False
- wordapp.Quit
- m = 0
- For i = 0 To UBound(arr)
- If Len(arr(i)) <> 0 Then
- If Not reg.test(arr(i)) Then
- m = m + 1
- n = 1
- brr(m, 1) = arr(i)
- Else
- Set mh = reg.Execute(arr(i))
- For k = 0 To mh.Count - 1
- n = n + 1
- brr(m, n) = mh(k)
- Next
- End If
- End If
- Next
- With Worksheets("导入")
- .Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|