![]() |
|
|
|
#1
|
||||
|
||||
|
The following should do the trick for selected text
Code:
Sub Highlight_Plus_Adjacent_Words()
Dim MyWords As Variant
Dim RngWords As Range
Dim oRng As Range
Dim i As Integer
MyWords = Split("one,two,three,four,five", ",")
Set oRng = Selection.Range
For i = 0 To UBound(MyWords)
Set RngWords = oRng
With RngWords.Find
Do While .Execute(FindText:=MyWords(i), MatchWholeWord:=True)
With RngWords
.Start = .Previous.Words(1).Start
.End = .Next.Words(1).Next.Words(1).End
.MoveEndWhile Chr(32), wdBackward
.HighlightColorIndex = wdYellow
.Collapse 0
If .Start >= oRng.End Then Exit Do
End With
Loop
End With
Next i
lbl_Exit:
Set oRng = Nothing
Set RngWords = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
| Tags |
| adjacent, highlight, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to delete the two non-adjacent rows in a table Word
|
beginner | Word | 2 | 01-05-2015 05:47 AM |
How to conditionally format cells in Col. A if it matches adjacent cell in Col. B?
|
alshcover | Excel | 2 | 06-03-2014 12:50 PM |
Word Macro to find and delete rows that contain adjacent cells containing "."
|
AlexanderJohnWilley | Word VBA | 7 | 11-08-2012 10:15 AM |
| Conditional Formatting Expiration Dates Based on Text in Adjacent Cell | Frogggg | Excel | 1 | 10-25-2011 08:44 PM |
| find - reading highlight - highlight all / highlight doesn't stick when saved | bobk544 | Word | 3 | 04-15-2009 03:31 PM |