以下代码感谢http://club.excelhome.net/home.php?mod=space&uid=3195546大侠提供思路和框架:
Sub word文档转excel汇总()
On Error Resume Next
[A2:AI250].ClearContents
Application.ScreenUpdating = False
Dim cPath$, cFile$, str$, i%, arr(1 To 500, 1 To 35)
Dim wordD As Word.Document
Dim Wordapp As Object
Set Wordapp = CreateObject("Word.Application")
cPath = ThisWorkbook.Path & "\"
cFile = Dir(cPath & "*.doc?")
Do While cFile <> ""
Set wordD = Wordapp.Documents.Open(cPath & cFile)
For i = 1 To wordD.Tables.Count
With wordD.Tables(i)
arr(i, 1) = i
arr(i, 2) = Replace(.Cell(2, 2).Range.Text, Chr(7), "")
arr(i, 3) = Replace(.Cell(2, 4).Range.Text, Chr(7), "")
arr(i, 4) = Replace(.Cell(2, 6).Range.Text, Chr(7), "")
arr(i, 5) = Replace(.Cell(3, 2).Range.Text, Chr(7), "")
arr(i, 6) = Replace(.Cell(3, 4).Range.Text, Chr(7), "")
arr(i, 7) = Replace(.Cell(3, 6).Range.Text, Chr(7), "")
arr(i, 8) = Replace(.Cell(4, 2).Range.Text, Chr(7), "")
arr(i, 9) = Replace(.Cell(4, 4).Range.Text, Chr(7), "")
arr(i, 10) = Replace(.Cell(5, 2).Range.Text, Chr(7), "")
arr(i, 11) = Replace(.Cell(5, 4).Range.Text, Chr(7), "")
arr(i, 12) = Replace(.Cell(6, 3).Range.Text, Chr(7), "")
arr(i, 13) = Replace(.Cell(6, 5).Range.Text, Chr(7), "")
arr(i, 14) = Replace(.Cell(7, 3).Range.Text, Chr(7), "")
arr(i, 15) = Replace(.Cell(7, 5).Range.Text, Chr(7), "")
arr(i, 16) = Replace(.Cell(8, 2).Range.Text, Chr(7), "")
arr(i, 17) = Replace(.Cell(8, 4).Range.Text, Chr(7), "")
arr(i, 18) = Replace(.Cell(9, 2).Range.Text, Chr(7), "")
arr(i, 19) = Replace(.Cell(9, 4).Range.Text, Chr(7), "")
arr(i, 20) = Replace(.Cell(9, 6).Range.Text, Chr(7), "")
arr(i, 21) = Replace(.Cell(10, 2).Range.Text, Chr(7), "")
arr(i, 22) = Replace(.Cell(13, 2).Range.Text, Chr(7), "")
arr(i, 23) = Replace(.Cell(13, 3).Range.Text, Chr(7), "")
arr(i, 24) = Replace(.Cell(14, 2).Range.Text, Chr(7), "")
arr(i, 25) = Replace(.Cell(14, 3).Range.Text, Chr(7), "")
arr(i, 26) = Replace(.Cell(14, 4).Range.Text, Chr(7), "")
arr(i, 27) = Replace(.Cell(15, 2).Range.Text, Chr(7), "")
arr(i, 28) = Replace(.Cell(15, 3).Range.Text, Chr(7), "")
arr(i, 29) = Replace(.Cell(15, 4).Range.Text, Chr(7), "")
arr(i, 30) = Replace(.Cell(16, 2).Range.Text, Chr(7), "")
arr(i, 31) = Replace(.Cell(16, 3).Range.Text, Chr(7), "")
arr(i, 32) = Replace(.Cell(16, 4).Range.Text, Chr(7), "")
arr(i, 33) = Replace(.Cell(19, 1).Range.Text, Chr(7), "") & Replace(.Cell(19, 2).Range.Text, Chr(7), "") _
& Replace(.Cell(19, 3).Range.Text, Chr(7), "") & Replace(.Cell(19, 4).Range.Text, Chr(7), "") & Chr(13) _
& Replace(.Cell(20, 1).Range.Text, Chr(7), "") & Replace(.Cell(20, 2).Range.Text, Chr(7), "") _
& Replace(.Cell(20, 3).Range.Text, Chr(7), "") & Replace(.Cell(20, 4).Range.Text, Chr(7), "")
arr(i, 34) = Replace(.Cell(23, 1).Range.Text, Chr(7), "") & Replace(.Cell(23, 2).Range.Text, Chr(7), "") _
& Replace(.Cell(23, 3).Range.Text, Chr(7), "") & Replace(.Cell(23, 4).Range.Text, Chr(7), "") _
& Replace(.Cell(23, 5).Range.Text, Chr(7), "") & Replace(.Cell(23, 6).Range.Text, Chr(7), "") & Chr(13) _
& Replace(.Cell(24, 1).Range.Text, Chr(7), "") & Replace(.Cell(24, 2).Range.Text, Chr(7), "") _
& Replace(.Cell(24, 3).Range.Text, Chr(7), "") & Replace(.Cell(24, 4).Range.Text, Chr(7), "") _
& Replace(.Cell(24, 5).Range.Text, Chr(7), "") & Replace(.Cell(24, 6).Range.Text, Chr(7), "")
arr(i, 35) = Replace(.Cell(29, 1).Range.Text, Chr(7), "")
End With
Next
wordD.Close
cFile = Dir
Loop
Set wordD = Nothing
Wordapp.Quit
Sheet1.Range("A2").Resize(i, 35) = arr
Application.ScreenUpdating = True
End Sub
|