Sub 批量提取()
Dim i As Integer, n As Integer
Dim arr()
Application.ScreenUpdating = False
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application") '新建Word对象
WordApp.Visible = True
Dim WordD As Object
ReDim arr(1 To 10000, 1 To 9)
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "*.doc*")
Do While f <> ""
Set WordD = WordApp.Documents.Open(lj & f)
With WordD.tables(1)
For i = 11 To 14
zd = Replace(.Cell(i, 3).Range.Text, Chr(13) & Chr(7), "")
If zd <> "" Then
n = n + 1
arr(n, 1) = Replace(.Cell(2, 2).Range.Text, Chr(13) & Chr(7), "")
arr(n, 2) = Replace(.Cell(6, 2).Range.Text, Chr(13) & Chr(7), "")
arr(n, 3) = Replace(.Cell(1, 4).Range.Text, Chr(13) & Chr(7), "")
arr(n, 4) = Replace(.Cell(i, 3).Range.Text, Chr(13) & Chr(7), "")
arr(n, 5) = Replace(.Cell(i, 4).Range.Text, Chr(13) & Chr(7), "")
arr(n, 6) = Replace(.Cell(i, 5).Range.Text, Chr(13) & Chr(7), "")
arr(n, 7) = Replace(.Cell(3, 4).Range.Text, Chr(13) & Chr(7), "")
arr(n, 8) = Replace(.Cell(5, 4).Range.Text, Chr(13) & Chr(7), "")
arr(n, 9) = Replace(.Cell(7, 2).Range.Text, Chr(13) & Chr(7), "")
End If
Next i
End With
WordD.Close False
f = Dir
Loop
Set WordD = Nothing
WordApp.Quit
[a1].CurrentRegion.Offset(1) = Empty
Range("a2").Resize(n, 9) = arr
Application.ScreenUpdating = True
MsgBox "完成"
End Sub
|