Macro to Import Tables from all Word documents in a folder to Sheet1

Hello All,
I am using Office 2010 and have found this code which works perfect
But I need the following amendments to the code

1) The code should read all the files in the Folder – now it runs on a single word document
2) It should paste the All Word table Data under the last available Row on Sheet1

Following is the code which needs to be amended:

Sub ImportTable()
Dim wdDoc As Object
Dim wdTbl As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim cRow As Long 'row index in Excel
Dim cCol As Integer 'column index in Excel
Dim wRow As Long 'row index in Excel
wdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc", , _
"Browse for file containing table to be imported")
If wdFileName = False Then Exit Sub '(user cancelled import file browser)
Set wdDoc = GetObject(wdFileName) 'open Word file
cRow = 0
With wdDoc
For Each wdTbl In wdDoc.tables
With wdTbl
'Test for To in Table Cell 1
If InStr(wdTbl.Cell(1, 1).Range.Text, "To") Then
'copy cell contents from Word table cells to Excel cells
For wRow = 1 To .Rows.Count
cRow = cRow + 1
For cCol = 1 To .Columns.Count
Cells(cRow, cCol) = WorksheetFunction.Clean(.Cell(wRow, cCol).Range.Text)
Next cCol
Next wRow
End If
End With
cRow = cRow + 1
Next
End With
Set wdDoc = Nothing
Set wdTbl = Nothing
End Sub
Thanks in advance
Top Contributor Asked on June 18, 2017 in VBA: Macros.
Add Comment
0 Answer(s)
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.