Thursday, November 10, 2011

Copy Specific column 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 column of a table and will paste to the excel


Here is the code-

Sub copy_first_column()
Dim doc As New Word.Application

doc.Visible = True
' TOOL -> REFRENCE-> MICROSOFT WORD
Documents.Open "C:\Documents and Settings\achamanlalko\Desktop\WORD TABLE.doc"
'' method 1
doc.ActiveDocument.Tables(1).Columns(1).Select
doc.Selection.Copy
ThisWorkbook.Activate
Sheets(1).Range("j1").Select
ActiveSheet.Paste

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


Word Table

Excel Macro File

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...