Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: macros VBA Word
hi all
i have a table in my word doc. i need to get the rowspan and colspan values of cells in this table from the vba code. becouse i want to convert it in a html doc.
 
if table is simple i.e. there is no rowspan and colspan then i have no problem. i use this code :
Function replace_tables()
' convert simple tables (no merged cells!)
Dim oRow As Row
Dim oCell As Cell
Dim sCellText As String
Dim tTable As Table
Dim noRows, noCells As Long
 
'StatusBar = "Convert tables..."
   
For Each tTable In ActiveDocument.Tables
    For Each oRow In tTable.Rows
        For Each oCell In oRow.Cells
            sCellText = oCell.Range
            sCellText = Left$(sCellText, Len(sCellText) - 2)
            If Len(sCellText) = 0 Then sCellText = " "
            sCellText = "<td>" & sCellText & "</td>"
            oCell.Range = sCellText
        Next oCell
        sCellText = oRow.Cells(1).Range
        sCellText = Left$(sCellText, Len(sCellText) - 2)
        sCellText = "<tr>" & vbCr & sCellText
        oRow.Cells(1).Range = sCellText
        sCellText = oRow.Cells(oRow.Cells.Count).Range
        sCellText = Left$(sCellText, Len(sCellText) - 2)
        sCellText = sCellText & vbCr & "</tr>"
        oRow.Cells(oRow.Cells.Count).Range = sCellText
    Next oRow
    sCellText = tTable.Rows(1).Cells(1).Range
    sCellText = Left$(sCellText, Len(sCellText) - 2)
    sCellText = "<table>" & vbCr & sCellText
    tTable.Rows(1).Cells(1).Range = sCellText
    noRows = tTable.Rows.Count
    noCells = tTable.Rows(noRows).Cells.Count
    sCellText = tTable.Rows(noRows).Cells(noCells).Range
    sCellText = Left$(sCellText, Len(sCellText) - 2)
    sCellText = sCellText & vbCr & "</table>"
    tTable.Rows(noRows).Cells(noCells).Range = sCellText
    tTable.ConvertToText Separator:=wdSeparateByParagraphs
Next tTable
 
End Function
 
but i want to write a code for table which has merged cells in it.
can somebody help me regarding this.. i am searching over the internet for my problem from last night.so please avoid pasting any link in solution, because i had already seen most of them.
Posted 13-Jan-13 23:00pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 250
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 DamithSL 125
4 Afzaal Ahmad Zeeshan 120
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100