converting word to excel

S

sathish

hi everyone,

i have a word document which contains tables. i want to convert the tables
into excel sheet. is there any simple way.
 
H

Helmut Weber

Hi Sathish,

if you really want to accelerate form 1 mph to mach 1, then:

Sub ExcelTest01()
Dim oExc As Excel.Application
Dim oWrk As Excel.Workbook
Dim oSht As Excel.Worksheet
Dim wTbl As Word.Table
Dim lCnt As Long
Dim lRow As Long
Dim lClm As Long
Dim x As Long
Dim y As Long

Set oExc = New Excel.Application
oExc.Workbooks.Add
Set oWrk = oExc.Workbooks(1)
For lCnt = oWrk.Worksheets.Count To 2 Step -1
oWrk.Worksheets(lCnt).Delete
Next
oExc.Visible = False ' maybe redundant
With ActiveDocument
For lCnt = 1 To .Tables.Count
Set oSht = oWrk.ActiveSheet
oSht.Name = "MySheet-" & Format(lCnt, "000")
Set wTbl = .Tables(lCnt)
lRow = wTbl.Rows.Count
lClm = wTbl.Columns.Count
For x = 1 To lClm
For y = 1 To lRow
oSht.Cells(y, x).Value = _
Left(wTbl.Cell(y, x).Range.Text, _
Len(wTbl.Cell(y, x).Range.Text) - 2)
Next
Next
If lCnt = .Tables.Count Then GoTo Ende
oWrk.Worksheets.Add After:=oSht
oExc.ActiveSheet.Name = "MySheet-" & Format(lCnt + 1, "000")
Next
End With
Ende:
MsgBox "ende (german for ""end"")"

oWrk.SaveAs "c:\test\yes.xls"
oWrk.Close
oExc.quit

Set oExc = Nothing
Set oWrk = Nothing
Set oSht = Nothing
Set wTbl = Nothing
End Sub

I know, this is very hard for a beginner.
Just give it a chance.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

sathish

Hi Weber,

thank you i got ur coding working and it helped me a lot in my work

regards
sathish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top