|
Sub 提取()
Dim i%, k%, arr(1 To 10000, 1 To 7), myPath$, myFile$, s1$, s2$, r%, c%, wdApp, d
Set d = CreateObject("scripting.dictionary")
Set wdApp = CreateObject("Word.Application")
Dim wdD As Word.Document
myPath = ThisWorkbook.Path & "\"
myFile = Dir(myPath & "*.doc?")
Do While myFile <> ""
Set wdD = wdApp.Documents.Open(myPath & myFile)
With wdD.Tables(1)
s1 = Replace(.Cell(1, 2).Range.Text, Chr(7), "")
s2 = Replace(.Cell(2, 2).Range.Text, Chr(7), "")
End With
With wdD.Tables(3)
For Each mycell In .Range.Cells
r = mycell.RowIndex
c = mycell.ColumnIndex
If c > d(r) Then d(r) = c
Next
For i = 2 To .Rows.Count
If Len(.Cell(i, d(i) - 3).Range.Text) = 2 Then
k = k + 1
arr(k, 1) = k
arr(k, 3) = s1
arr(k, 4) = s2
arr(k, 5) = Replace(.Cell(i, d(i) - 5).Range.Text, Chr(7), "")
End If
Next
End With
wdD.Close
myFile = Dir
Loop
wdApp.Quit
Set wdD = Nothing
Set wdApp = Nothing
Set d = Nothing
Range("A3").CurrentRegion.Offset(2).ClearContents
Range("A3").Resize(UBound(arr), 7) = arr
End Sub
|
|