wrsteam
asked on
Convert RTF to HTML using MS Word programatically
I have a VB6 legacy app with the following functionality:
1. Functions that retrieve RTF formatted documents as strings from a sql database.
2. Functions that parse through the RTF tags and insert additional data from the database.
3. One function that takes the final string and assigns it to the .body of an MS Outlook message.
This functionality, messy at best, was working fine until we switched from Outlook 2000 to Outlook 2003. Apparently Outlook 2003 doesn't support RichText, so now all the RTF tags are showing up in the email body. It's not feasible at this point to update all the sql stored RTF documents or the first two functionality points mentioned above...so my only other option is to convert the RTF to HTML on the fly before sending it to Outlook.
I'VE TRIED MANY RTF TO HTML CONVERTERS inside the code and none of them convert the indentation and spacing correctly. The application does have the ability to preview the outlook email message body before sending it by storing the RTF string inside a RichTextBox. I manually copied the preview from the RichTextBox, pasted it in word and saved it as an HTML and it looks perfect. I would basically like to do that programmatically.
I've searched far and wide and despite several forums on the subject, still couldn't find any VB6 examples of this.
Any help would be greatly appreciated.
Thanks in advance!
1. Functions that retrieve RTF formatted documents as strings from a sql database.
2. Functions that parse through the RTF tags and insert additional data from the database.
3. One function that takes the final string and assigns it to the .body of an MS Outlook message.
This functionality, messy at best, was working fine until we switched from Outlook 2000 to Outlook 2003. Apparently Outlook 2003 doesn't support RichText, so now all the RTF tags are showing up in the email body. It's not feasible at this point to update all the sql stored RTF documents or the first two functionality points mentioned above...so my only other option is to convert the RTF to HTML on the fly before sending it to Outlook.
I'VE TRIED MANY RTF TO HTML CONVERTERS inside the code and none of them convert the indentation and spacing correctly. The application does have the ability to preview the outlook email message body before sending it by storing the RTF string inside a RichTextBox. I manually copied the preview from the RichTextBox, pasted it in word and saved it as an HTML and it looks perfect. I would basically like to do that programmatically.
I've searched far and wide and despite several forums on the subject, still couldn't find any VB6 examples of this.
Any help would be greatly appreciated.
Thanks in advance!
ASKER
I appreciate the solution, however, as I mentioned in my original post:
The RTF doc is in the form of a string with RTF tags...so it's not a file and I therefore have no path.
That said, the line of code you proposed will not work:
Set wordDoc = wordApp.Documents.Open("co mplete_pat h_to_the_r tf_documen t")
Any other ideas?
The RTF doc is in the form of a string with RTF tags...so it's not a file and I therefore have no path.
That said, the line of code you proposed will not work:
Set wordDoc = wordApp.Documents.Open("co
Any other ideas?
If you have the possibility, you can work with temp files. First, save your RTF string data into a temp file; then, use MS Word to convert into HTML with the code provided in my previous post; last, if you need it, open the HTML file and get the content into a string in order to set as body of your e-mail. Finally, delete both temp files (.rtf and .html).
ASKER
Okay, but I don't know how to get the content from the string into the temp file...nor do I know how to get the content of the html file back into a string. Can you please provide some sample code that does this?
Thanks so much. You've been extremely helpful!!
Thanks so much. You've been extremely helpful!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
AMAZING. I can't even begin to tell you how helpful your solution has been!!! I have literally been pulling my hair out trying to figure this out...not to mention the grief I'm getting from my client. You are truly an EXPERT!
Thanks,
Rob
Thanks,
Rob
Open in new window