Option Explicit
Sub TEST()
Dim wdApp As Word.Application, strRngText$
Dim ar, br, cr, i&, r&, strFileName$, strPath$
Application.ScreenUpdating = False
On Error Resume Next
With [A2].CurrentRegion
.Offset(2).Clear
ar = .Resize(10 ^ 3)
r = 2
End With
br = [{2,3,4,5,6,8,9,10,11,12,13,14,16,17,18,19,20,21,22,23,24,25,26}]
cr = [{2,1;10,1;6,5;2,3;2,5;3,1;3,3;3,5;4,1;4,3;4,5;5,1;5,3;5,5;6,1;6,3;7,1;7,3;7,5;8,1;8,4;9,2;9,4}]
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = New Word.Application
End If
strPath = ThisWorkbook.Path & "\"
strFileName = Dir(strPath & "*.doc*")
Do Until strFileName = ""
With wdApp.Documents.Open(strPath & strFileName)
r = r + 1: ar(r, 1) = r - 2
With .tables(1)
For i = 1 To UBound(br)
strRngText = .Cell(cr(i, 1), cr(i, 2)).Range.Text
ar(r, br(i)) = Left(strRngText, Len(strRngText) - 2)
Next i
End With
.Close False
End With
strFileName = Dir
Loop
[A1].Resize(r, UBound(ar, 2)) = ar
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|