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

Replacing Bold Text

Status
Not open for further replies.

pcsmurf

IS-IT--Management
Apr 26, 2002
47
0
0
GB
I have a VBA script to convert any text that it finds in bold in a document to be tagged as follows:

<P>This paragraph contains some <b>bold text</b> and some plain text.</p>

This works when only part of a paragraph contains bold text but if the whole paragraph is in bold the output I get:

<p><b>This paragraph is all in bold</p>
<p></b>The closing bold tag appears at the start of the next paragraph</p>

My code is:

Rem Checking for bold
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Font.Bold = True

With Selection.Find
.Text = ""
.Replacement.Text = "<b>^&</b>"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

The <p> and </p> tags are added later, but I am assuming that I need to somehow make the .Replacement.Text value = <b> + the value of the paragraph but without the paragraph marker + </b> + paragraph marker but I am unable to work out how to do this.
 
Hi pcsmurf,

Try:
Code:
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Font.Bold = True
  .Text = ""
  .Replacement.Text = "<b>^&</b>"
  .Forward = True
  .Wrap = wdFindContinue
  .Format = True
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Text = "<b>^p</b>"
  .Replacement.Text = "^p"
  .Forward = True
  .Wrap = wdFindContinue
  .Execute Replace:=wdReplaceAll
End With
Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top