Sub ImportWordTables()
'Imports cells (3,2) and (4,2) from Word document Tables 1-10
Dim wdDoc As Word.Document
Dim wdFileName As Variant
Dim TableNo As Integer 'number of tables in Word doc
Dim iTable As Integer 'table number index
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column 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
With wdDoc
TableNo = wdDoc.tables.Count
If TableNo = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
ElseIf TableNo > 10 Then
TableNo = 10
'Else TableNo is actual number of tables between 1 and 9
End If
Range("A1") = "Table #"
Range("B1") = "Cell (3,2)"
Range("C1") = "Cell (4,2)"
For iTable = 1 To TableNo
With .tables(iTable)
'copy cell contents from Word table cells to Excel cells in column B and C
Cells(iTable + 1, "A") = iTable
Cells(iTable + 1, "B") = WorksheetFunction.Clean(.cell(3, 2).Range.Text)
Cells(iTable + 1, "C") = WorksheetFunction.Clean(.cell(4, 2).Range.Text)
End With
Next iTable
End With
Set wdDoc = Nothing
End Sub