PDA

View Full Version : Getting my script to highlight in different colours...



jamespope
06-12-2006, 06:16 AM
Hello everyone,

Sorry for what will probably be a very basic query and thanks for taking the time to look at it.

I'm trying to get my macro to highlight 'resigns' (and variants) and 'appoints' (and variants) in different colours. I've come up with this:

' highlighting appointment
Selection.Find.ClearFormatting
Selection.Range.HighlightColorIndex = wdYellow
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = "<[Aa]ppoin[a-z]@>"
.Replacement.Text = Text
.Replacement.Font.Bold = False
.Replacement.Font.Color = wdColorBlack
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


' highlighting resignation
Selection.Find.ClearFormatting
Selection.Range.HighlightColorIndex = wdViolet
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = "<[Rr]esig[a-z]@>"
.Replacement.Text = Text
.Replacement.Font.Bold = False
.Replacement.Font.Color = wdColorBlack
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

---
but this doesn't seem to change the highlight colour at all :doh:

i'm probably using the wrong command but that's all i could see after messing around with some macro recordings.

any pointers very welcome!

Cheers,:beerchug:

James

TonyJollans
06-18-2006, 02:42 PM
Hi James,

Welcome to VBAX!

This question seems to have slipped thrugh the net so you may have solved it on your own by now. If not, and for anyone who comes along later ...

Find and Replace can Highlight but you cannot control the colour it uses - it just takes whatever the 'current' one on the Formatting Toolbar is. So that is the one you must change. Try using ...Options.DefaultHighlightColorIndex = wdViolet