Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word - Html string to Formatted text 1

Status
Not open for further replies.

JSpicolli

Programmer
Apr 2, 2004
208
US
Hi,

I have a VB6 app that reads XML data to generate a word report.

Some of the data I read out of the XML are html strings, instead of plain text.

I tried
Code:
With ActiveDocument.Range.Find
    .ClearFormatting
    .MatchCase = False
    .MatchWildcards = True
    .Text = "[<][bB][>]*[<]/[bB][>]"
    .Replacement.Font.Bold = True
    .Execute Replace:=wdReplaceAll
End With

But it did not work.

Does anyone have any other methods for converting html into formatted text for word?

Thanks,
[stars guaranteed for answer]
 
The above would not remove the tags. It seems that it would simply look for that string, and bold it, not change the string characters themselves. Some suggestions:

Do your search string including the tags; do the replacement as the string without the tags, THEN format it as per whatever the tags did.

How are you bringing in the content?

Gerry
 
Thanks, I will try that.

The content comes from XML that is generated from Oracle.

My VB app, traverses the DOM, pulling out Data as it is needed and then inserts it into a word document.

 
Actually, that isn't going to work as the <b> and <i> tags are the only markers I have to determine what formatting to apply to the text.
 
OK. Then, do this, or a variation thereof

make three variables, 1 string 2 boolean (YesBold and YesItalic)

1. do the search
2. on Execute = true, make a Selection of the search result
3. copy it into string variable
4. delete the selection, and collapse it
5. parse through the string variable using Select Case or some other logic testing, to check for <b> and/or <i>
6. set your boolean values YesBold, YesItalic accordingly
7. strip out the tags from your string variable
8. insert the string at the selection point
9. format according to your boolean results

Essentially this is the same as my original suggestion - just more detail on how you many determine what the format will be on the replaced text. Again, you search and strip off the tags, format as per what the tags did.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top