|
- Sub test()
- Dim wordapp As Object
- Dim mydoc As Object
- Set wordapp = CreateObject("word.application")
- Set mydoc = CreateObject("word.document")
- Dim r%, i%
- Dim myapth$, myname$
- Dim brr(1 To 1000, 1 To 10)
- Application.ScreenUpdating = False
- mypath = ThisWorkbook.Path & ""
- myname = "记录.docx"
- Set mydoc = wordapp.Documents.Open(mypath & myname)
- With mydoc
- m = 0
- For i = 1 To .Paragraphs.Count
- ss = .Paragraphs(i).Range.Text
- If Len(ss) > 2 Then
- If Left(ss, 2) = "名称" Then
- m = m + 1
- brr(m, 1) = m
- n = 1
- End If
- n = n + 1
- brr(m, n) = Split(ss, vbTab)(1)
- End If
- Next
- .Close False
- End With
- With Worksheets("sheet1")
- .UsedRange.Offset(2, 0).ClearContents
- .Range("a3").Resize(m, UBound(brr, 2)) = brr
- End With
- wordapp.Quit
- End
- End Sub
复制代码 |
|