Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2018, 07:39 AM
musicgold musicgold is offline Highlighting multiple non-contiguous words? Windows 7 64bit Highlighting multiple non-contiguous words? Office 2010 32bit
Novice
Highlighting multiple non-contiguous words?
 
Join Date: Jun 2018
Posts: 3
musicgold is on a distinguished road
Default Highlighting multiple non-contiguous words?

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
Thanks
Reply With Quote
  #2  
Old 06-07-2018, 11:40 AM
d4okeefe d4okeefe is offline Highlighting multiple non-contiguous words? Windows 10 Highlighting multiple non-contiguous words? Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

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
to this
Code:
Selection.Range.HighlightColorIndex = wdYellow
Reply With Quote
  #3  
Old 06-07-2018, 12:10 PM
musicgold musicgold is offline Highlighting multiple non-contiguous words? Windows 7 64bit Highlighting multiple non-contiguous words? Office 2010 32bit
Novice
Highlighting multiple non-contiguous words?
 
Join Date: Jun 2018
Posts: 3
musicgold is on a distinguished road
Default

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?
Reply With Quote
  #4  
Old 06-07-2018, 12:22 PM
d4okeefe d4okeefe is offline Highlighting multiple non-contiguous words? Windows 10 Highlighting multiple non-contiguous words? Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

You can step through to see what's happening using F8.
Code:
Do While .Execute
carries out the Selection.Find operation. In this case example, all of the user-selected text has been marked "whtcolor", and the while loop changes each one that is marked.
Reply With Quote
  #5  
Old 06-07-2018, 01:00 PM
musicgold musicgold is offline Highlighting multiple non-contiguous words? Windows 7 64bit Highlighting multiple non-contiguous words? Office 2010 32bit
Novice
Highlighting multiple non-contiguous words?
 
Join Date: Jun 2018
Posts: 3
musicgold is on a distinguished road
Default

Thank you.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlighting multiple non-contiguous words? Novice needs: Complicated running totals adding substracting non contiguous cells contiguous columns innkeeper9 Excel 5 08-30-2016 04:43 PM
Contiguous grouping derohanes Excel 4 10-30-2015 04:41 PM
Highlighting multiple non-contiguous words? How to make it highlight blocks of text (words) without highlighting extra space @end 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
Highlighting multiple non-contiguous words? Macro for highlighting specific number of words icsjohn Word VBA 2 12-07-2011 06:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft