|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim wordapp As Object
- Dim mydoc As Word.Document
- Dim reg As Object
- Dim i%, r%
- Dim arr(1 To 200, 1 To 9)
- Set reg = CreateObject("vbscript.regexp")
- Set wordapp = CreateObject("word.application")
- With reg
- .Global = True
- .MultiLine = True
- .Pattern = "\b[A-Z]\..*?\x20"
- End With
- Set mydoc = wordapp.Documents.Open(ThisWorkbook.Path & "" & "word题库.doc")
- m = 0
- For i = 1 To mydoc.Paragraphs.Count
- ss = mydoc.Paragraphs(i).Range.Text
- If Left(ss, 1) Like "[0-9]" Then
- m = m + 1
- c = 4
- arr(m, 3) = ss
- End If
- If Left(ss, 1) Like "[A-Z]" Then
- Set matchs = reg.Execute(ss)
- For j = 0 To matchs.Count - 1
- arr(m, j + c) = matchs(j)
- Next
- c = c + matchs.Count
- End If
- Next
- Range("a2").Resize(UBound(arr), 9) = arr
- mydoc.Close False
- wordapp.Quit
- End Sub
-
-
复制代码 |
|