Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 11-04-2013, 04:56 AM
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

Try:
Code:
Sub ConditionalHighlight()
Application.ScreenUpdating = False
Dim vFindText As Variant, StrWrds As String, i As Long, Rng As Range
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 = False
      .MatchAllWordForms = False
      .MatchWholeWord = True
      .Wrap = wdFindStop
      .Text = vFindText(i)
      .Replacement.Text = ""
      .Execute
   End With
    Do While .Find.Found
      Set Rng = .Duplicate.Words.First
      With Rng
        If LCase(.Next.Words.First.Characters.First) = .Next.Words.First.Characters.First Then
          If .Sentences.First.Start = .Start Then
            Rng.Duplicate.HighlightColorIndex = wdBrightGreen
          Else
            With .Previous.Words.First
              If InStr(StrWrds, "," & Trim(.Text) & ",") > 0 Then
                Rng.Duplicate.HighlightColorIndex = wdBrightGreen
              ElseIf LCase(.Characters.First) = .Characters.First Then
                Rng.Duplicate.HighlightColorIndex = wdBrightGreen
              End If
            End With
          End If
        End If
      End With
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
Next i
Application.ScreenUpdating = True
End Sub
__________________
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