troubleshooting Question

Convert HTML to RTF, remove tables, copy RTF and text to clipboard

Avatar of joex
joex asked on
12 Comments1 Solution698 ViewsLast Modified:
If anyone knows how to implement the VB.Net code at bottom in c++, please let me know.


            Dim fileName as String = "htmlToRtf"
            Dim wd As Object = CreateObject("word.application")

            ' open html in word
            wd.Documents.Open(fileName:=fileName + ".htm")
            ' remove tables
            Dim tblToConvert As Object
            For Each tblToConvert In wd.ActiveDocument.Tables
                tblToConvert.ConvertToText(vbTab, True)
            ' create RTF and text files
            wd.ActiveDocument.SaveAs(fileName:=fileName + ".rtf", FileFormat:=wdFormatRTF)
            wd.ActiveDocument.SaveAs(fileName:=fileName + ".txt", FileFormat:=wdFormatText)
            wd = Nothing

            ' read in RTF and text files
            Dim rtfFile As String
            Dim sr As System.IO.StreamReader = New System.IO.StreamReader(fileName + ".rtf")
            rtfFile = sr.ReadToEnd

            Dim textFile As String
            sr = New System.IO.StreamReader(fileName + ".txt")
            textFile = sr.ReadToEnd

            ' store RTF and text in clipboard
            Dim sData As String
            Dim dataObject As New DataObject
            dataObject.SetData(DataFormats.Text, True, textFile)
            dataObject.SetData(DataFormats.Rtf, True, rtfFile)


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros