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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2k - bold with tags?

Status
Not open for further replies.

RustyAfro

Programmer
Jan 12, 2005
332
US
Is there any way in Word to bold an area using some sort of tag word recognizes? (ie <b>BoldMe</b>). I am trying to understand how Word internally "remembers" what part of character(s) are bolded and if possible, input it manually with some kind of special character tag. I understand I can .font.bold but if there was a way to use a tag, that would be easier for me.

The reason is I am automatically inputting entire pages of templates from a database into word, and I want to be able to control what parts are bold, italic, underline, etc in the text. I suppose I could make my own tags and build a custom module that loops through the whole document doing the appropriate action, but if there is a better way I'd love to use it.
 
Think I answered my own question. Looked online and found that word stores it's formatting with positional references in binary.

This post was VERY helpful:


It had the below modified code to format all the html tags appropriately. Worked like a charm =)

Code:
Sub FormatFromTags()
    ' Change HTML-style tags to Word formatting
    ' Bold
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Bold = True
    With Selection.Find
        .Text = "\<[Bb]\>(*)\</[Bb]\>"
        .Replacement.Text = "\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    'Italic
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Italic = True
    With Selection.Find
        .Text = "\<[Ii]\>(*)\</[Ii]\>"
        .Replacement.Text = "\1"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ' Underline
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Underline = wdUnderlineSingle
    With Selection.Find
        .Text = "\<[Uu]\>(*)\</[Uu]\>"
        .Replacement.Text = "\1"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top