Pages

Thursday, November 10, 2011

Copy Specific Row from a word table to excel

If you want to copy a specific column from a word table to excel.For Example the below code will copy the first row(header) of a table and will paste into the excel.

Sub copy_first_row()
Dim doc As New Word.Application

doc.Visible = True
' TOOL -> REFRENCE-> MICROSOFT WORD
Documents.Open "C:\Documents and Settings\achamanlalko\Desktop\WORD TABLE.doc"
Documents(ActiveDocument.Name).Activate
'
' method 1
ActiveDocument.Tables(1).Rows(1).Range.Copy
ThisWorkbook.Sheets(1).Range("j1").PasteSpecial xlPasteValues

' method 2
k = 1
For i = 1 To ActiveDocument.Tables(1).Range.Columns.Count
Cells(1, i) = ActiveDocument.Tables(1).Cell(1, i).Range.Text
Cells(1, i) = Application.WorksheetFunction.Clean(Cells(1, i))
k = k + 1
Next
doc.Quit
End Sub

Word Document

Excel Macro File

No comments:

Post a Comment