Click here to Skip to main content
15,881,742 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 :
VB
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

1 solution

 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900