Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2017, 05:52 AM
jamesnavoy jamesnavoy is offline issue with highlight macro word 2010 Windows 7 32bit issue with highlight macro word 2010 Office 2010 32bit
Novice
issue with highlight macro word 2010
 
Join Date: Jan 2017
Posts: 2
jamesnavoy is on a distinguished road
Default issue with highlight macro word 2010


Hi guys, I'm looking for help with a simple find and highlight words macro. this macro i was trying out seems to only be able to highlight with the currently active highlighted color, not the replacement color mentioned in the macro so I was wondering why that might be happening? and secondly i would like to do 3 set of the same routine, different colors for different words. how do i ammend this to achieve it please?

Code:
Sub ListChange()
Dim r As Range
Dim MyList() As String
Dim i As Long
MyList = Split("challenging,difficult,down by,", ",")
For i = 0 To UBound(MyList())
   Set r = ActiveDocument.Range
      With r.Find
         .Text = MyList(i)
         .Replacement.Highlight = wdGreen
         .Execute Replace:=wdReplaceAll
      End With
Next
End Sub

Last edited by macropod; 01-30-2017 at 12:27 AM. Reason: Added code tags to restore formatting
Reply With Quote
  #2  
Old 01-29-2017, 07:26 AM
gmayor's Avatar
gmayor gmayor is offline issue with highlight macro word 2010 Windows 10 issue with highlight macro word 2010 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Change as follows:
Code:
Sub ListChange()
Dim r As Range
Dim MyList() As String
Dim i As Long
    MyList = Split("challenging,difficult,down by,", ",")
    For i = 0 To UBound(MyList())
        Set r = ActiveDocument.Range
        With r.Find
            Do While .Execute(FindText:=MyList(i))
                Select Case i
                    Case Is = 0
                        r.HighlightColorIndex = wdYellow
                    Case Is = 1
                        r.HighlightColorIndex = wdTurquoise
                    Case Else
                        r.HighlightColorIndex = wdGreen
                End Select
                r.Collapse 0
            Loop
        End With
    Next
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-29-2017, 08:32 AM
jamesnavoy jamesnavoy is offline issue with highlight macro word 2010 Windows 7 32bit issue with highlight macro word 2010 Office 2010 32bit
Novice
issue with highlight macro word 2010
 
Join Date: Jan 2017
Posts: 2
jamesnavoy is on a distinguished road
Default

thanks gmayor, sorted it out and edited for what i needed now. tnx very much for the quick response.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
issue with highlight macro word 2010 VBA word macro to highlight a selected text just like a spell checker Pankaj Word VBA 1 10-14-2016 03:48 AM
Macro to highlight repeated words in word file and extract into excel file aabri Word VBA 1 06-14-2015 07:20 AM
issue with highlight macro word 2010 Macro Question: Need help making a macro to highlight the first word in every sentence LadyAna Word 1 12-06-2014 10:39 PM
issue with highlight macro word 2010 Macro to highlight text between 2 points in word 2010 jsilva1950 Word VBA 2 04-25-2013 12:21 AM
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 06:51 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