Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In Word 2003, I need either a macro or a regular expression to find bolded text strings beginning at the left hand side of the page. Once the string is found, I need to put a marker, [/bold], at the end of the string. The strings end in either a period, colon, semi-colon, comma, period, tab character, or a period followed by a paragraph mark.

    Thank you in advance for your replies.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by HowdeeDoodee View Post
    In Word 2003, I need either a macro or a regular expression to find bolded text strings beginning at the left hand side of the page. Once the string is found, I need to put a marker, [/bold], at the end of the string.
    Here's a rough macro:

    Code:
    Sub MarkBolds()
    With Selection
        ' To top of document
        .HomeKey Unit:=wdStory
        ' Set Find parameters
        With .Find
            .ClearFormatting
            .Text = ""
            .Font.Bold = True   ' Search for runs of bold
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Do
            If .Find.Execute = False Then Exit Do
            ' Found text at start of line?
            If .Information(wdFirstCharacterColumnNumber) = 1 Then
                If .Characters(Selection.Characters.Count).Text = vbCr Then
                    ' Back off from paragraph break
                    .MoveEnd wdCharacter, -1
                    .Collapse wdCollapseEnd
                    .TypeText "[/bold]"
                    .MoveDown wdParagraph, 1, wdMove
                Else
                    .Collapse wdCollapseEnd
                    .TypeText "[/bold]"
                End If
            Else
                .Collapse wdCollapseEnd
            End If
        Loop
        ' Clear Find parameters
        With .Find
            .ClearFormatting
            .Format = False
        End With
    End With
    End Sub
    This macro doesn't check the last character, other than backing off of paragraph breaks to place the [/bold] before it.

  4. #3
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much. This macro will save me a ton of work. Thanks again.

Posting Permissions

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