Copying word tables to Excel

P

Pawan

Hello..
I have a word file with hundred of pages and hundred of tables. I want to
copy all these tables in one excel sheet. Is it possible by writing some code?

Help is appreciated.
Thank you

Regards,
Pawan
 
G

George Lee

Remember to always Google for answers first. There are lot of sites already
with similar code. The gist of the solution is below and is run from Word.
There might be some problems depending on how the charts are designed, and
error checking is needed. First, you will need to add a reference to the
Microsoft Excel Object Library (in VBA, Tools->References menu item).

Public Sub CopyTables()
On Error GoTo MyErrorHandler

Dim sourceDocument As Document
Set sourceDocument = ActiveDocument

Dim excelApplication As Excel.Application
Set excelApplication = GetObject(, "Excel.Application")

Dim targetWorksheet As Excel.Worksheet
Set targetWorksheet = excelApplication.ActiveSheet

Dim tableCount As Long
Dim myTable As Table
For Each myTable In sourceDocument.Tables
tableCount = tableCount + 1
myTable.Range.Copy

targetWorksheet.Cells(tableCount, 2).Activate 'Place the table as
needed
targetWorksheet.Paste

DoEvents
Next

Exit Sub

MyErrorHandler:
MsgBox "CopyCharts" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf &
"Description: " & Err.Description
End Su
 
Top