View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal[_2_] Robert Crandal[_2_] is offline
external usenet poster
 
Posts: 158
Default Load data from Word into Excel

"Claus Busch" wrote

IMO is that the easiest and quickest way to import the data from a
table. You can delete formats and borders after the import.


Hi Claus. I was finally able to create a solution. In case you're
curious, here's what it looks like. I tweaked your code
slightly:

'------------------------------------------------------------------
Sub ImportFromWord()

Dim objWord As Object
Dim oTable As Table
Dim oRow As Row
Dim r As Integer

' Load target Word document
Set objWord = CreateObject("Word.Application")
objWord.documents.Open ("C:\word_data.doc")
objWord.Visible = True
objWord.Activate

Set oTable = objWord.ActiveDocument.Tables(1)

' Go through all rows of Word table
For r = 1 To oTable.Rows.Count
Set oRow = oTable.Rows(r)

' Paste data back into Excel. This Word table has 6 columns
Sheet1.Cells(r, 1).Value = oRow.Cells(1).Range.Text
Sheet1.Cells(r, 2).Value = oRow.Cells(2).Range.Text
Sheet1.Cells(r, 3).Value = oRow.Cells(3).Range.Text
Sheet1.Cells(r, 4).Value = oRow.Cells(4).Range.Text
Sheet1.Cells(r, 5).Value = oRow.Cells(5).Range.Text
Sheet1.Cells(r, 6).Value = oRow.Cells(6).Range.Text
Next r

' Quit Word
objWord.Application.Quit

End Sub
'----------------------------------------------------------------

The data pasted from each cell of the Word table contains
two weird whitespace or bullet characters at the end, but I'm
sure I can trim off the two characters.

Robert