Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding Bold Codes (Word 97/XP)

    Is there a way to Find where a bolded text started and where it ended?

    For example, 2 paragraphs, the user selected both paragraphs and applied Bold. When doing a Search for Bold, it should highlight both paragraphs instead of only finding the first paragraph?

  2. #2
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding Bold Codes (Word 97/XP)

    This can't be done? <img src=/S/bwaaah.gif border=0 alt=bwaaah width=123 height=15>

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    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.

  4. #4
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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:

    (B1)first paragraph(B2)
    (B1)(B2)
    (B1)(B2)
    (B1)second paragraph(B2)

    instead of:
    (B1)first paragraph

    second paragraph(B2)

    <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

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

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    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>

    Developed and tested in Word 2002. YMMV.

  7. #7
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding Bold Codes (Word 97/XP)

    Genius!

    I can't say enough -- I'm just going to sit here and <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Finding Bold Codes (Word 97/XP)

    Oh, I'm sure I'll be upstaged within 24 hours because this is not very efficient code. Nevertheless, with a fast CPU, it's quite good enough. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •