tags:

views:

2807

answers:

2

I use Visual Basic and an automation interface to retrieve strings from an external application. These strings contain simple html formatting codes (<b>, <i>, etc.). Is there any easy function in Visual Basic for Word to insert these strings into a word document and convert the html formatting codes to word formatting?

A: 

AFAIK there is no builtin function to do that in VBA. You will have to write it yourself, which would be not too difficult if you restirct it to parse <b>, <i>, <a> and <p>, for example. All other tags would have to be ignored.

Treb
+3  A: 

Here's a link to add HTML to the clipboard using VB:

http://support.microsoft.com/kb/274326

Once you have the HTML on the clipboard, paste it into your word doc using something like this:

ActiveDocument.Range.PasteSpecial ,,,,WdPasteDataType.wdPasteHTML

This is pretty much the equivalent of you cutting and pasting it in manually.

Jonathan Yee