View Single Post
 
Old 09-08-2016, 08:16 PM
ChrisOK ChrisOK is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: Sep 2016
Posts: 54
ChrisOK is on a distinguished road
Thumbs up Solutions

Thanks for the help and the cross-post etiquette link- I read it and have done/will continue to my best to make sure no one is left hanging. (that's one thing that's so frustrating - coming across a post that's EXACTLY what you need an answer to but no one ever posted a solution.. Either (a) the poor soul just gave up or (b) found an answer elsewhere and never came back to share it.. We'll never know which - but for anyone who comes across this one, I've got at least 2 solutions that newbies like me can review, (hopefully learn from) and use as they wish to help them too! It never ceases to amaze me how there's so many diff ways to achieve the same outcome.. interesting to read each line to see how the methods differ... (well, at least it is to me as someone who's still learning)


Method 1 Code (MatchWildcards=False):

Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "Contractor Shall"
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindStop
  .Format = True
  .MatchWildcards = False
  .Execute
  End With
  Do While .Find.Found
  .Duplicate.Paragraphs.First.Range.HighlightColorIndex = wdYellow
  .Start = .Duplicate.Paragraphs.First.Range.End
  .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub

Method 2 Code (Alternative):
Code:
Sub Highlight_Paragraph()
  Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
  Do While .Execute(FindText:="Contractor Shall")
  oRng.Paragraphs(1).Range.HighlightColorIndex = wdYellow
  oRng.Collapse 0
  Loop
  End With
  lbl_Exit:
  Set oRng = Nothing
  Exit Sub
  End Sub
Reply With Quote