Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-03-2013, 07:36 PM
macropod's Avatar
macropod macropod is offline Is the following too complex for find/replace macro? Windows 7 32bit Is the following too complex for find/replace macro? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,514
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

You could use something like:
Code:
Sub ConditionalHighlight()
Application.ScreenUpdating = False
Dim vFindText As Variant, StrWrds As String, i As Long
vFindText = "Note,Notes"
vFindText = Split(vFindText, ",")
StrWrds = ",The,Each,"
For i = LBound(vFindText) To UBound(vFindText)
  With ActiveDocument.Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Format = False
      .MatchWildcards = True
      .Wrap = wdFindStop
      .Text = "<[! ]{1,}> " & vFindText(i) & ">"
      .Replacement.Text = ""
      .Execute
   End With
    Do While .Find.Found
      If InStr(StrWrds, "," & Trim(.Duplicate.Words.First.Text) & ",") > 0 Then
        .Duplicate.HighlightColorIndex = wdBrightGreen
      End If
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
Next i
Application.ScreenUpdating = True
End Sub
where 'StrWrds' contains the list of words that must precede the words of interest. Note that you'll need to input the singular and plural forms of each word of interest.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find - Replace Macro using a table list mdw Word 0 08-01-2013 04:36 PM
Is the following too complex for find/replace macro? Find and Replace Format macro issue Jack Word VBA 2 12-12-2012 09:24 PM
macro or find/replace JamesVenhaus Word 2 02-27-2012 03:34 PM
Is the following too complex for find/replace macro? Complex Find and Replace paulkaye Word 1 11-13-2011 04:23 AM
Find and Replace Macro - A Better Way Tribos Word VBA 0 10-08-2008 03:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:46 AM.


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