ok, I have approx 1000 word documents that contain three tables. I have code that will let me extract all of the tables and enter them onto an excel sheet; however, I have to run it for each document, will then have to figure out how to merge the data to one sheet, and truth be told I only need 5 pieces of data from the first table and then all of the information from the second table. I could care less about the third table.
All of the word files are formatted the exact same, unfortunately it wasn't as a form.
Here is code courtesy of Damon Ostrander which will pull just two cells from each table and do multiple tables. How can I modify it to pull the specific cells from the first table, all of the data from the second and then none from the third?
Hopefully the code will come out formatted....
The second option is how could I merge all of the separate sheets into one sheet. The problem being that I only need specific data and the sheets are formatted as if they are three tables. So no headers to refer to...
Thanks,
Rap
All of the word files are formatted the exact same, unfortunately it wasn't as a form.
Here is code courtesy of Damon Ostrander which will pull just two cells from each table and do multiple tables. How can I modify it to pull the specific cells from the first table, all of the data from the second and then none from the third?
Hopefully the code will come out formatted....
Code:
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
The second option is how could I merge all of the separate sheets into one sheet. The problem being that I only need specific data and the sheets are formatted as if they are three tables. So no headers to refer to...
Thanks,
Rap