不清楚你的具体要求,先琢磨着写了一个
Sub 提取()
Dim i%, k%, arr(1 To 10000, 1 To 7), myPath$, myFile$, s1$, s2$, r%, c%, wdApp, d, temp
Set d = CreateObject("scripting.dictionary")
Set wdApp = CreateObject("Word.Application")
Dim wdD As Word.Document
myPath = ThisWorkbook.Path & "\"
myFile = Dir(myPath & "*.doc?")
On Error Resume Next
Do While myFile <> ""
k = k + 1
arr(k, 5) = ""
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
temp = Replace(.Cell(i, 2).Range.Text, Chr(7), "")
If Err.Number = 0 Then
arr(k, 1) = k
arr(k, 2) = Split(myFile, ".")(0)
arr(k, 3) = s1
arr(k, 4) = s2
If Len(arr(k, 5)) > 0 Then arr(k, 5) = arr(k, 5) & ","
arr(k, 5) = arr(k, 5) & temp
End If
End If
Err.Clear
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
|