HTML codes convert to Attribute

P

PeterJ

Client sends documents with typesetting codes - how do I find/replace the
bold, italic and bold/italic and add the attribute to the text in html code
and remove the html code in a loop? Is it possible to do in one macro guys?

This is a test paragraph showing both the <B>bold terms<B> and words, as
well as the <I>italicized areas<I> and the <BI>bold, italicized
words.<BI>
 
D

Doug Robbins - Word MVP

Dim myrange As Range, srange As Range, erange As Range
Dim i As Long, j As Long
Dim fcode As String
For i = 1 To 3
If i = 1 Then
fcode = "\<B\>*\<B\>"
j = 3
ElseIf i = 2 Then
fcode = "\<I\>*\<I\>"
j = 3
Else
fcode = "\<BI\>*\<BI\>"
j = 4
End If
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:=fcode, Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
If i = 1 Then
myrange.Font.Bold = True
ElseIf i = 2 Then
myrange.Font.Italic = True
Else
myrange.Font.Bold = True
myrange.Font.Italic = True
End If
Set srange = myrange.Duplicate
Set erange = myrange.Duplicate
srange.End = srange.start + j
srange.Delete
erange.start = erange.End - j
erange.Delete
Loop
End With
Next i

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

PeterJ

Wow, thank you Doug you are fabulous!

Doug Robbins - Word MVP said:
Dim myrange As Range, srange As Range, erange As Range
Dim i As Long, j As Long
Dim fcode As String
For i = 1 To 3
If i = 1 Then
fcode = "\<B\>*\<B\>"
j = 3
ElseIf i = 2 Then
fcode = "\<I\>*\<I\>"
j = 3
Else
fcode = "\<BI\>*\<BI\>"
j = 4
End If
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:=fcode, Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
If i = 1 Then
myrange.Font.Bold = True
ElseIf i = 2 Then
myrange.Font.Italic = True
Else
myrange.Font.Bold = True
myrange.Font.Italic = True
End If
Set srange = myrange.Duplicate
Set erange = myrange.Duplicate
srange.End = srange.start + j
srange.Delete
erange.start = erange.End - j
erange.Delete
Loop
End With
Next i

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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