Load data from Word into Excel
Hi Robert,
Am Thu, 2 May 2013 13:56:01 -0700 schrieb Robert Crandal:
What does your final code look like for this entire
function?
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:\Users\Claus Busch\Desktop\Test.docx")
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
For r = 1 To 6
Columns(r).TextToColumns Destination:=Cells(1, r), _
DataType:=xlDelimited, Tab:=True, fieldinfo:=Array(1, 1)
Next
' Quit Word
objWord.Application.Quit
End Sub
Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
|