I ran into a similar problem yesterday and found some good info on a Google Group...
I savaged the code quite severely to get it to work in my particular situation, mostly because I was extracting it from straight Word Text, not a table, but for what it is worth...
If you want to write code to do it, here is an example that just creates a
message box for each cell in the table showing the value. This could be
converted to create a record in Access and you could adapt it to do this for
a number of documents, each with 1 or more tables.
Is this a route you might pursue?
Private Sub cmdExtract_Click()
On Error GoTo Err_Handler
Dim strPath As String
Dim strValue As String
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim wdTbl As Object 'Word.Table
Dim wdRow As Object 'Word.Row
Dim wdCol As Object 'Word.Column
Dim wdCell As Object 'Word.Cell
strPath = "C:\Example.doc"
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(strPath)
If wdDoc.Tables.Count > 0 Then
Set wdTbl = wdDoc.Tables(1)
For Each wdRow In wdTbl.Rows
For Each wdCol In wdTbl.Columns
strValue = wdTbl.Cell(wdRow.Index, wdCol.Index).Range.Text
If Len(strValue) > 2 Then
strValue = Left$(strValue, Len(strValue) - 2)
Else
strValue = ""
End If
MsgBox strValue
Next wdCol
Next wdRow
End If
MsgBox "Done", vbInformation
Exit_Handler:
On Error Resume Next
If Not wdDoc Is Nothing Then
wdDoc.Close
Set wdDoc = Nothing
End If
If Not wdApp Is Nothing Then
wdApp.Quit
Set wdApp = Nothing
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
Mike
EchoVue.com
|