Automation: Inserting HTML text into Word 2000

J

John

I'm using Word 2000 to produce an output document from a VB application.

I'm fine inserting text, images etc at bookmarks within a Word template
file, but when I insert text which contains HTML tags, these are inserted as
plain text rather than HTML. For instance you end up seeing "<B>Bold
Here</B>" rather than just a bolded formatting of the words "Bold Here"

Word 2000 can obviously handle HTML, because if you paste in text copied
from a browser, you get it rendered as HTML rather than plain text.

I'm using code like this to insert the text:

Word.Application.ActiveDocument.Bookmarks.Item("IntroParagraph").Range.Text=
"<B>Bold Here</B>"

Suggestions gratefully received!
Thanks, John
 
J

Jonathan West

Hi John,

The Text property of a range is just that - text. If you want to format the
text then you'll have to strip off the tags and apply the formatting as
separate VBA commands.

Alternatively, if you can get the formatted text you want loaded onto the
clipboard and you can then insert it using the Paste method. But it is not a
simple matter of loading up text with tags into the clipboard and then
expecting Windows to magically realise that the tags are formatting rather
than the text you inserted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top