Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 05-27-2020, 05:01 AM
macropod's Avatar
macropod macropod is offline Highlight keywords in the pasted text Windows 7 64bit Highlight keywords in the pasted text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,363
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

Since you can't us a BackgroundPatternColor property as a Find parameter, you'll need to revert to a nested loop. Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, arrWords, i As Long, RGB As Long
arrWords = Array("keyword1 & keyword2", "keyword1", "keyword2", "keyword3")
Set Rng = Selection.Range
Rng.Paste
For i = 0 To UBound(arrWords)
  Select Case i
    Case 0: RGB = wdColorGray05
    Case 1: RGB = wdColorPaleBlue
    Case 2: RGB = wdColorLightOrange
    Case 3: RGB = wdColorPink
  End Select
  With Selection
    With .Find
      .ClearFormatting
      .Text = arrWords(i)
      .Replacement.Text = ""
      .Format = False
      .Forward = True
      .Wrap = wdFindStop
    End With
    Do While .Find.Execute
      If .InRange(Rng) = False Then Exit Do
      If .Shading.BackgroundPatternColor = wdColorAutomatic Then .Shading.BackgroundPatternColor = RGB
      .Collapse wdCollapseEnd
    Loop
  End With
  Rng.Select
Next
Application.ScreenUpdating = True
End Sub
Insert your preferred RGB colour values in place of the named constants in the Select Case statement.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
I am trying to delete text of any format between two bold, recurring keywords or symbols qubie Word VBA 8 03-04-2020 03:20 PM
Highlight keywords in the pasted text how do I make pasted text the same size as the text it's being pasted into? David Lee Word 6 08-16-2015 10:46 AM
Highlight keywords in the pasted text Help with finding multiple keywords in a single document then highlight navyguy Word 2 01-03-2014 12:48 PM
Trying to highlight pasted text in a macro goldengate Word VBA 0 09-14-2010 09:41 PM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:51 PM.


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