Consulting

Results 1 to 4 of 4

Thread: insert sign and bold after found searched phrase

  1. #1
    VBAX Regular
    Joined
    Jan 2018
    Posts
    58
    Location

    insert sign and bold after found searched phrase

    Hi,
    How to modify this code to insert and bold foundend phrase from array, in below code it changes only first word: AAA inestead of whole phrase AAA BBB
    Many Thanks


    Sub insert_bold_after_second_word()
    
    
          
          'Application.ScreenUpdating = False
        Dim x As Long, i As Long, ArrFnd()
        ArrFnd = Array("AAA BBB", "CCC DDD EEE")
        For x = 0 To UBound(ArrFnd)
            With ActiveDocument.Range
                With .Find
                    .ClearFormatting
                    .Replacement.ClearFormatting
                    .Text = ArrFnd(x)
                    .Highlight = False
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindStop
                    .Format = False
                    .MatchWildcards = True
                    .Execute
                End With
                Do While .Find.Found
                    i = i + 1
                    .Start = .Words.First.Start
                    .End = .Words.First.End
                    .MoveEndWhile " ", -1
                    .InsertAfter ChrW(9658)
                     .End = .End + 1
                    .Font.Color = 204
                    .Font.bold = True
                    .Collapse wdCollapseEnd
                    .Find.Execute
                Loop
            End With
        Next
    End Sub

  2. #2
    To simply make the found words Bold

    Sub insert_bold_after_second_word()
          'Application.ScreenUpdating = False
        Dim x As Long, i As Long, ArrFnd()
        ArrFnd = Array("AAA BBB", "CCC DDD EEE")
        For x = 0 To UBound(ArrFnd)
            With ActiveDocument.Range
                With .Find
                    .ClearFormatting
                    .Replacement.ClearFormatting
                    .Text = ArrFnd(x)
                    .Highlight = False
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindStop
                    .Format = False
                    .MatchWildcards = True
                    .Execute
                End With
                Do While .Find.Found
                    'i = i + 1
                    '.Start = .Words.First.Start
                    '.End = .Words.First.End
                    '.MoveEndWhile " ", -1
                    '.InsertAfter ChrW(9658)
                     '.End = .End + 1
                    '.Font.Color = 204
                    .Font.Bold = True
                    .Collapse wdCollapseEnd
                    .Find.Execute
                Loop
            End With
        Next
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Jan 2018
    Posts
    58
    Location
    ok, but this part of code that You reject is important for me, I want also insert sign and change font color:

    Sub insert_bold_after_second_word()
          'Application.ScreenUpdating = False
        Dim x As Long, i As Long, ArrFnd()
        ArrFnd = Array("AAA BBB", "CCC DDD EEE")
        For x = 0 To UBound(ArrFnd)
            With ActiveDocument.Range
                With .Find
                    .ClearFormatting
                    .Replacement.ClearFormatting
                    .Text = ArrFnd(x)
                    .Highlight = False
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindStop
                    .Format = False
                    .MatchWildcards = True
                    .Execute
                End With
                Do While .Find.Found
                    'i = i + 1
                    '.Start = .Words.First.Start
                    '.End = .Words.First.End
                    '.MoveEndWhile " ", -1
                     .InsertAfter ChrW(9658) 'important
                     '.End = .End + 1
                      .Font.Color = 204   'important
                    .Font.Bold = True     'important
                    .Collapse wdCollapseEnd
                    .Find.Execute
                Loop
            End With
        Next
    End Sub
    Last edited by dagerr; 03-05-2018 at 07:21 AM.

  4. #4
    VBAX Regular
    Joined
    Jan 2018
    Posts
    58
    Location
    ok, I just removed aposthropes in lines where code should work and it is seems to work properly.

Posting Permissions

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