Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Convert Word tables to Excel

Hi,

Below is the code to convert word tables to word. But I am trying to convert
them into Excel. I have not been successful so far. Can somebody tell me
where I am goign wrong or how to do it.

Sub MergeTables()

'

' MergeTables Macro

' Macro created 1/18/2008 by PENNDOT

'

Dim aDoc As Document

Dim SrcDoc As Document

Dim tbl1 As Table

Dim tbl2 As Table

Dim Tbl1Rng As Range

Dim Tbl2Rng As Range

Dim A As Integer

Dim B As Integer

Dim C As Integer



Dim MyText$



Set aDoc = ActiveDocument

Set SrcDoc = ActiveDocument

Set tbl1 = aDoc.Tables(1)

Set tbl2 = aDoc.Tables(2)



Set SrcDoc = Documents.Add



SrcDoc.Range.InsertAfter _

"HD2,HD2,HD2,HD2,HD2" & vbCr



'First Row

For A = 2 To 3

Set Tbl1Rng = tbl1.Cell(A, 2).Range

'Remove end of cell marker

Tbl1Rng.MoveEnd wdCharacter, -1

MyText$ = MyText$ & "," & Tbl1Rng

Next

'Remove first comma

MyText$ = Mid(MyText$, 2, Len(MyText$))



For C = 1 To 3

Set Tbl2Rng = tbl2.Cell(1, C).Range

Tbl2Rng.MoveEnd wdCharacter, -1

MyText$ = MyText$ & "," & Tbl2Rng

Next



SrcDoc.Range.InsertAfter MyText$ & vbCr ' Row 1



'Subsequent rows

For B = 2 To 4

MyText$ = ","

For C = 1 To 3

Set Tbl2Rng = tbl2.Cell(B, C).Range

Tbl2Rng.MoveEnd wdCharacter, -1

MyText$ = MyText$ & "," & Tbl2Rng

Next

MyText$ = Mid(MyText$, 2, Len(MyText$))

SrcDoc.Range.InsertAfter "," & MyText$ & vbCr

Next



Set aDoc = Nothing

Set Tbl1Rng = Nothing

Set Tbl2Rng = Nothing



With SrcDoc.Range

.ConvertToTable ","

End With



End Sub

Thank You
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating tables from Excel in Word zil Excel Discussion (Misc queries) 1 May 30th 07 12:48 AM
updating word-tables from excel yshridhar Excel Discussion (Misc queries) 0 May 24th 07 06:22 AM
Excel tables to Word--Best Solution? erik_gregory Excel Discussion (Misc queries) 3 March 6th 07 06:33 AM
copying word tables into excel vmwexway Excel Worksheet Functions 0 March 1st 06 03:33 PM
How do I convert word data (not in tables) into excel format? resret29 Excel Worksheet Functions 2 October 9th 05 01:25 AM


All times are GMT +1. The time now is 06:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"