View Single Post
 
Old 06-07-2014, 06:25 PM
mrayncrental mrayncrental is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Feb 2014
Posts: 15
mrayncrental is on a distinguished road
Default How to search for 2 words at the same time

I currently have a macro that searches for "STOP:" in a table. I would like to also search for "NEXT:" at the same time (want to change the paragraph to red.

How can I do this?

See current code below. Thanks!

Code:
   Dim r As Range
    Dim Para As Paragraph
    Dim aCell As Cell
    Dim myTable As Table
    
        
'Find all Tip Paragraphs and turn red
 
  
  Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting
 
  Set myTable = ActiveDocument.Tables(1)
  For Each aCell In myTable.Columns(3).Cells
    Set r = aCell.Range
    For Each Para In aCell.Range.Paragraphs
      With Para.Range
        With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "STOP:"
            .Format = True
            .Forward = True
            .Wrap = wdFindStop
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            .Execute
        End With
             
        Do While .Find.Found = True
            With .Duplicate
                If .InRange(r) Then
                    .Paragraphs.First.Range.Font.Color = wdColorRed
                End If
            End With
            .Collapse wdCollapseEnd
            .Find.Execute
        Loop
      End With
    Next
   Next
 

End Sub
Reply With Quote