|
- Sub test()
- Dim d As Object
- Dim wordapp As Object
- Dim mydoc As Word.Document
- Dim i%, j%
- Dim mypath$, myname$
- Dim arr, brr(1 To 1000, 1 To 8)
- Dim reg As New RegExp
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- ss = "A.10月17日 B.3月12日"
- With reg
- .Global = True
- .Pattern = "([A-D]).(.*?)(?=[A-D].|$)"
- Set mh = .Execute(ss)
- End With
- mypath = ThisWorkbook.Path & ""
- myname = "题库.docx"
- If Dir(mypath & myname) = "" Then
- MsgBox mypath & myname & "不存在!"
- End If
- Set wordapp = CreateObject("word.application")
- wordapp.Visible = True
- Set mydoc = wordapp.Documents.Open(mypath & myname)
- m = 0
- With mydoc
- For i = 1 To .Paragraphs.Count
- Set aa = .Paragraphs(i)
- If aa.Range.ListFormat.ListValue > 0 Then
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = aa.Range.Text
- Else
- If reg.test(aa.Range.Text) Then
- Set mh = reg.Execute(aa.Range.Text)
- For j = 0 To mh.Count - 1
- xh = Asc(mh(j).SubMatches(0)) - 62
- nr = mh(j).SubMatches(1)
- brr(m, xh) = nr
- Next
- Else
- Select Case Left(aa.Range.Text, 2)
- Case "答案"
- brr(m, 7) = Mid(aa.Range.Text, 4)
- Case "解析"
- brr(m, 8) = Mid(aa.Range.Text, 4)
- End Select
-
- End If
- End If
- Next
- End With
- mydoc.Close False
- wordapp.Quit
- With Worksheets("sheet1")
- .UsedRange.Offset(1, 0).Clear
- With .Range("a2").Resize(m, UBound(brr, 2))
- .Value = brr
- .WrapText = True
- .Borders.LineStyle = xlContinuous
- End With
- End With
- End Sub
复制代码 |
|