Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    May 2002
    Location
    Charlotte, North Carolina, USA
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bolding all text in brackets (2002/XP)

    Long code fragment moved to attachment by HansV (also preserves indentation)

    I am working on code to bold all text within brackets in a document. I have it working, but it eternally loops and will not stop now! Help! Can someone look at this code and let me know what I need to change?
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bolding all text in brackets (2002/XP)

    Change the three occurrences of wdFindContinue to wdFindStop

  3. #3
    Star Lounger
    Join Date
    May 2002
    Location
    Charlotte, North Carolina, USA
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bolding all text in brackets (2002/XP)

    That is exactly what I needed. THANK YOU! (and sorry about the code, next time it will be in a txt file)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bolding all text in brackets (2002/XP)

    By the way, here is a much shorter version, using a wildcard search:

    Sub BoldBrackets()
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    ' Search for [ followed by any number of characters followed by ]
    .Text = "[*]"
    ' Replace by the search text
    .Replacement.Text = "^&"
    ' But make it bold
    .Replacement.Font.Bold = True
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    ' Use wildcards
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    End With
    End Sub

  5. #5
    Star Lounger
    Join Date
    May 2002
    Location
    Charlotte, North Carolina, USA
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bolding all text in brackets (2002/XP)

    Thank you! I took your code, much cleaner than mine, and was able to get this up and running.
    Thanks for your help!

Posting Permissions

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