HI
Ok Thanks for this. I'm grateful for your help.
I find it works really well when I run it on the original text. It finds the entries in the StrFnd list.
Curiously though it misses entries which are added subsequently. For example , if i open the document and run the macro it highlights all correctly. If I then type in an item of target text to see if it would find that too , it doesn't.
To experiment further , I saved the document with the newly-added text included. On re-opening , I find the macro doesn't find the new text. I am at a loss to explain this.
I did make some changes to the StrFnd list to search for the precise terms I'm looking to highlight , of course , but otherwise I'm running it as shown :
Code:
Sub HiLightList()
'This macro finds and highlights all the words in the StrFnd list below
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long, j As Long
StrFnd = UCase("LP|LPs|Vinyl|Record|Records|CD|CDs|DVD|DVDs|Music|Programme|Programmes|Cassette|Cassettes|Tape|Tapes|45s|78s|78 rpm|78rpm")
For i = 0 To UBound(Split(StrFnd, "|"))
Select Case i Mod 6
Case 0: j = 3
Case 1: j = 4
Case 2: j = 5
Case 3: j = 6
Case 4: j = 7
Case 5: j = 16
End Select
Options.DefaultHighlightColorIndex = j
'This line specifies colour for all matches
Options.DefaultHighlightColorIndex = wdPink
Set Rng = ActiveDocument.Range
With Rng.Find
.ClearFormatting
.Text = "[!^13]@<" & Split(StrFnd, "|")(i) & ">[!^13]{1,}"
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
I can't think that these small changes would cause it to ignore some of the entries to the list.
I'll attach again a fuller version of my target text , I'd be intersted to see if you can create the same phenomen.
Thanks again.