Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2014, 06:25 PM
mrayncrental mrayncrental is offline How to search for 2 words at the same time Windows 7 64bit How to search for 2 words at the same time Office 2007
Novice
How to search for 2 words at the same time
 
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
  #2  
Old 06-08-2014, 03:08 AM
macropod's Avatar
macropod macropod is offline How to search for 2 words at the same time Windows 7 32bit How to search for 2 words at the same time Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps something based on:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Text = "STOP:[!^13]@NEXT:"
  With .Replacement
    .ClearFormatting
    .Text = "^&"
    .Font.ColorIndex = wdRed
  End With
  .Forward = True
  .Wrap = wdFindStop
  .Format = True
  .MatchWildcards = True
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for date and then apply mutliple search criteria in huge dataset maxtymo Excel 2 12-01-2013 04:52 AM
2013 search results take a long time - they fill in as results in reverse date order themookman Outlook 0 10-11-2013 12:01 PM
Multiple words, one search return2300 Word VBA 0 08-30-2013 12:26 PM
How to search for 2 words at the same time Search for words starting in capitals surreytom Word VBA 3 04-01-2012 01:41 AM
How to search for 2 words at the same time Perform a search for alternative words jungkim Word 2 03-24-2012 07:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:59 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft