Pages

Thursday, November 10, 2011

Copy Specific range from a word table and paste into excel

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


Sub copy_all_the_data_skip_header()
Dim doc As New Word.Application
Dim abc As Word.Range
doc.Visible = True
' TOOL -> REFRENCE-> MICROSOFT WORD
Documents.Open "C:\Documents and Settings\achamanlalko\Desktop\WORD TABLE.doc"
' it will copy from (row 2 col 1) till (row 7 and col 3) will ignore the first row.

Set abc = doc.ActiveDocument.Range( _
Start:=doc.ActiveDocument.Tables(1).Cell(2, 1).Range.Start, _
End:=doc.ActiveDocument.Tables(1).Cell(7, 3).Range.End)
abc.Select
doc.Selection.Copy
ThisWorkbook.Activate
Sheets(1).Range("a2").Select
ActiveSheet.Paste
doc.Quit
End Sub

Word Document
Excel Macro File

No comments:

Post a Comment