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.
<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.