![]() |
#1
|
|||
|
|||
![]()
Hi,
I use the following code to highlight a selected word, or line or paragraph. However, when I select two or more non-contiguous words (by keeping the CTRL key pressed), and apply this macro, it only highlights the last selected word. What can I do to get the macro to highlight all of selected words? Code:
Selection.Expand Unit:=wdWord Selection.Range.HighlightColorIndex = wdYellow Selection.MoveRight Unit:=wdCharacter, Count:=1 |
#2
|
|||
|
|||
![]()
Your question interested me, and I found an interesting solution here.
It's a bit more complicated than your code, but will work. All you need to do is change this line Code:
Selection.Range.Case = wdTitleWord Code:
Selection.Range.HighlightColorIndex = wdYellow |
#3
|
|||
|
|||
![]()
Thanks d4okeefe. It works like a charm.
BTW do you know the purpose of the Do While loop in the code? What does it check for? |
#4
|
|||
|
|||
![]()
You can step through to see what's happening using F8.
Code:
Do While .Execute |
#5
|
|||
|
|||
![]()
Thank you.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
innkeeper9 | Excel | 5 | 08-30-2016 04:43 PM |
Contiguous grouping | derohanes | Excel | 4 | 10-30-2015 04:41 PM |
![]() |
seortm | Word | 3 | 03-30-2015 08:12 AM |
Highlighting multiple word instances in text | gekser | Word VBA | 9 | 07-10-2014 05:46 AM |
![]() |
icsjohn | Word VBA | 2 | 12-07-2011 06:44 PM |