Perhaps:
Option Explicit Sub GetTableData() 'Note: this code requires a reference to the Word object model. 'See under the VBE's Tools|References. Application.ScreenUpdating = False Dim wdApp As New Word.Application, wdDoc As Word.Document Dim strFolder As String, strFile As String, WkSht As Worksheet Dim c As Long, r As Long, i As Long, j As Long strFolder = GetFolder: If strFolder = "" Then GoTo ErrExit Set WkSht = ActiveSheet r = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row strFile = Dir(strFolder & "\*.docx", vbNormal) While strFile <> "" Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) r = r + 1: c = 1 WkSht.Cells(r, c).Value = Split(strFile, ".docx")(0) With wdDoc With .Tables(1) For i = 2 To 4 Step 2 For j = 2 To 4 c = c + 1 WkSht.Cells(r, c).Value = Split(.Cell(j, i).Range.Text, vbCr)(0) Next Next For i = 2 To 4 Step 2 For j = 6 To 10 c = c + 1 WkSht.Cells(r, c).Value = Split(.Cell(j, i).Range.Text, vbCr)(0) Next Next For j = 14 To 22 For i = 3 To 5 c = c + 1 WkSht.Cells(r, c).Value = Split(.Cell(j, i).Range.Text, vbCr)(0) Next Next End With With .Tables(2) For j = 2 To 7 For i = 3 To 5 c = c + 1 WkSht.Cells(r, c).Value = Split(.Cell(j, i).Range.Text, vbCr)(0) Next Next For j = 9 To 11 For i = 3 To 5 c = c + 1 WkSht.Cells(r, c).Value = Split(.Cell(j, i).Range.Text, vbCr)(0) Next Next End With .Close SaveChanges:=False End With strFile = Dir() Wend ErrExit: wdApp.Quit Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function




Reply With Quote