Re: Finding Bold Codes (Word 97/XP)

I don't know about Word 97, but in Word 2002 there's an option to "Highlight all items found in ['Main Document' or 'Headers and Footers']" when using Find. It still won't tell you, however, whether 2 adjacent paragraphs were made bold together or separately.

Re: Finding Bold Codes (Word 97/XP)

It seems like when search for attributes such as Bold, it will only select it up to the end of paragraph even if they were formatted as a whole. I just tried this. I created 2 paragraphs, separated with 2 hard returns, selected both and applied Bold. When I did a search, it only highlighted the first paragraph.

I am trying to search for Bold, unbold it and add (B1) at the beginning and (B2) at the end. So if search will only select the first paragraph, I will end up with:

Re: Finding Bold Codes (Word 97/XP)

Perhaps what you need to do, after finding the first instance of bold formatting, is record the selection, collapse it to the start, add the (B1) tag, re-instate the selection, move forward 1 character, and then search for Not Bold formatting. You'd then need to decide where to add the (B2) tag if the first instance of non-bold formatting was a new paragraph - at the start of that paragraph, or before the paragraph mark of the previous paragraph (because that paragraph mark would itself have bold formatting).

Re: Finding Bold Codes (Word 97/XP)

<P ID="edit" class=small>(Edited by jscher2000 on 21-Aug-03 18:35. See the line marked THIS DOES NOT WORK and the following line.)</P>I don't know if this is compatible with the code in the other long thread, but it will do something similar to what you request. I wrote it using HTML-style tags, but you can use any marker you like. I'm not sure if this can be generalized to handle all kinds of formatting with a few parameters, or whether you will need to duplicate it for other kinds of formatting.

<pre>Sub BoldToTagged()
' Surround bolded text with and tags, and unbold it
' Use a standard formatting find for Bold
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Font.Bold = True
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Find and fix for every instance of Bold in the body
While Selection.Find.Execute() = True
With Selection
Do
' Extend the selection one character and check status
.MoveEnd unit:=wdCharacter, Count:=1
If .End = ActiveDocument.Content.End - 1 Then
'End of document, exit loop and tag
Exit Do
ElseIf ActiveDocument.Range(.End - 1, .End).Font.Bold <> True Then
'Exceeded bold zone, back up one character, exit loop and tag
.MoveEnd unit:=wdCharacter, Count:=-1
Exit Do
End If
Loop
' Clear the bold attribute from the selected text
.Font.Bold = False
'If the last character is a space, back up one more time
If Right(.Text, 1) = " " Then
.MoveEnd unit:=wdCharacter, Count:=-1
End If
' Surround with tags, unless it was just a space we backed off from
' If Len(.Text) > 0 Then 'THIS DOES NOT WORK (.Text is next 1 character, it's never 0)
If .End - .Start > 0 Then
.InsertBefore ""
.InsertAfter ""
End If
' Position for next search
.Collapse Direction:=wdCollapseEnd
End With
Wend
End Sub</pre>

You will see that I'm trying to not tag trailing spaces or single spaces that have the bold attribute. I think those are annoying. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>