PDA

View Full Version : Table-in-Table to Single Table



Kumarcoolz
07-10-2014, 02:47 AM
Hi Guys,
Need your help on this ...... i work primarily on word document. I get the data in form of tables from the website and change the format of the table. The content that i copy from the website has data on table inside another table.... it goes to maximum of 5 sub-level with one table inside another. but i have to bring the same data into a single table.

this becomes a tedious process of copy+paste which could go on for very long hours:crying:. i wanted to reduce this unwanted non-productive work. Google was not very graceful with its search results:bug:. I dont know well about VBA and not sure if it is possible at all. Kindly give me ideas or approach to get this started

i have attached the sample document of my final requirement. 11923. you can see that both format look the same when viewed in 'Print Preview'.

Regards & Thanks
Kumar

Kumarcoolz
07-30-2014, 05:40 AM
i happened to do some googling and get some codes and manipulated to some extent..



Sub RetrieveTableItems()
Dim iResponse As Integer
Dim oRow As Row
Dim oCell As Cell
Dim sCellText As String
Dim r As Integer
' Turn on error checking.
On Error GoTo ErrorHandler

r = 1
For Each tTable In ActiveDocument.Tables

' Loop through each row in the table.
tTable.Select

iResponse = MsgBox("Table found. Find next?", 68)
If iResponse = vbNo Then GoTo skiptable 'User chose to leave search.

For Each oRow In ActiveDocument.Tables(r).Rows

' Loop through each cell in the current row.
For Each oCell In oRow.Cells

sCellText = oCell.Range
' Remove table cell markers from the text.
sCellText = Left$(sCellText, Len(sCellText) - 2)
MsgBox sCellText

Next oCell

Next oRow
skiptable:

r = r + 1
Next tTable



ErrorHandler:
If Err <> 0 Then
Dim Msg As String
Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description _
& Chr(13) & "Make sure there is a table in the current document."
MsgBox Msg, , "Error"
End If

End Sub




But this code work only on the second table in the attached word document.
Can some tell me why it doesn't run on the first table...

Automating this will save a lot of time... :help