Converting HTML Code to Table in MS Word

khawarameer

Board Regular
Joined
Jun 2, 2009
Messages
152
Dear All,

I have an html code available in an excel column (Please refer below table). My aim is to send that code to Word Document using mail merge and convert the code in to a Table when it is merged in word document. However when excel column in merged in Word Document the html code is not converted to Table and is shown as html code. Please help in this regard.

Observation_HeadingObservation_ContentTable
Documents not found in scanning Other IndividualWhile reviewing Account Opening Forms , it was noticed that following documents were not found while checking AOF’s and amendments.<table> <tbody> <tr> <td> <p>Account Number</p> </td> <td> <p>Branch</p> </td> <td> <p>Account Title</p> </td> <td> <p>Opening Date</p> </td> <td> <p>Category</p> </td> <td> <p>Observations</p> </td> </tr> <tr> <td> <p>1006950357</p> </td> <td> <p>404</p> </td> <td> <p>Newtown Inc</p> </td> <td> <p>02/24/2020</p> </td> <td> <p>SA</p> </td> <td> <p>branch visit report not found while reviewing Account Opening form.</p> </td> </tr> <tr> <td> <p>5001181195</p> </td> <td> <p>5620</p> </td> <td> <p>ABC &amp; Compay</p> </td> <td> <p>11/19/2019</p> </td> <td> <p>CA</p> </td> <td> <p>S.S card not found while reviewing Account Opening form</p> </td> </tr> </tbody></table>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
This is my idea

1. Copy the HTML code to Notepad
2. Save as 'mycode.html' file
3. Open 'mycode.html' and select everything and then copy
4. Paste into an Excel file

You now have the data in the spreadsheet properly organized in Excel.
Further do what you want with the data.
 

Attachments

  • Untitled-1.png
    Untitled-1.png
    13.1 KB · Views: 161
Upvote 0
Thank you @navic for your response however this is not what i want. Actually i want to pass the code from excel to word using mail merge and once code is in word then i want to covert it to table.
 
Upvote 0
Here's an Excel macro you can build on. It reads the HTML table code from C2 on the active sheet and adds it as a table in a new Word document.

You must set the references noted at the top of the code, via Tools -> References in the VBA editor.

VBA Code:
'References:
'Microsoft HTML Object Library
'Microsoft Word nn.0 Object Library

Public Sub Convert_HTML_Code_To_Word_Table()

    Dim HTMLdoc As HTMLDocument, HTMLdoc2 As HTMLDocument
    Dim table As HTMLTable
    Dim tRow As HTMLTableRow, tCell As HTMLTableCell
    Dim HTMLfile As String
    Dim wdApp As Word.Application
    Dim wdDoc As Word.document
    Dim wdTable As Word.table
    
    HTMLfile = Environ("temp") & "/table.html"
    Open HTMLfile For Output As #1
    Print #1, Range("C2").Value
    Close #1
    
    Set HTMLdoc2 = New HTMLDocument
    Set HTMLdoc = HTMLdoc2.createDocumentFromUrl(HTMLfile, "")
    While HTMLdoc.readyState <> "complete"
        DoEvents
    Wend
    Kill HTMLfile
    
    Set table = HTMLdoc.getElementsByTagName("TABLE")(0)
    
    Set wdApp = New Word.Application
    wdApp.Visible = True
    
    Set wdDoc = wdApp.Documents.Add
    Set wdTable = wdDoc.Tables.Add(Range:=wdDoc.Range, NumRows:=table.Rows.Length, NumColumns:=table.Rows(0).Cells.Length)
    wdTable.Borders.Enable = True
    
    For Each tRow In table.Rows
        For Each tCell In tRow.Cells
            wdTable.Cell(tRow.RowIndex + 1, tCell.cellIndex + 1).Range.Text = tCell.innerText
        Next
    Next
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top