Re: Deriving the word (range) at cursor location
- From: MAB <MAB@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 3 Dec 2006 11:45:00 -0800
Thank you Jay, it works great.
I am having a problem though. After manually setting the background color
(Yellow) with one of the Highlight drop down buttons (Formatting toolbar),
your code will not remove the background color. If I use your code but set a
specific color (wdColorAqua) then set the color back to wdColorAutomatic then
rerun your code, the color is removed. Any thoughts on why?
BTW, thank you and Jonathan very much for all the help!
"Jay Freedman" wrote:
On Sun, 3 Dec 2006 17:24:34 -0000, "Jonathan West" <jwest@xxxxxxxx>.
wrote:
"MAB" <MAB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A49660B6-1572-4A16-B1B7-C909A7B91B47@xxxxxxxxxxxxxxxx
I should have been clearer. When the user single left clicks inside a
word,
I want to obtain the word (Range).
You were perfectly clear
I can't use Selection because nothing is
selected, only a the cursor's position inside a word.
The Selection object exists even when you have a flashing cursor. The Type
property of the Selection object tells you what sort of selection it is.
wdSelectionIP referes to the flashing insertion point.
If the user single left clicks on a word with a certain barckground color
(previously applied programmatically by another app of mine), I want to
remove the background color for all instances of that word. Once I obtain
the word, I can iterate thru the document's Words collection to remove all
instances.
Jay's code does give you the word in which the insertion point is flashing.
Try it!
MAB,
Following on from your further description, please don't iterate
through the Words collection -- it's almost the slowest possible way
(only iterating through the Characters collection is slower). Instead,
once you have the word, use a Find operation in a loop to search the
document:
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Text = Selection.Words(1).Text
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = False
Do While .Execute
oRg.Shading.BackgroundPatternColor = wdColorAutomatic
Loop
End With
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
- Follow-Ups:
- Re: Deriving the word (range) at cursor location
- From: Jay Freedman
- Re: Deriving the word (range) at cursor location
- References:
- Re: Deriving the word (range) at cursor location
- From: Jay Freedman
- Re: Deriving the word (range) at cursor location
- From: Jonathan West
- Re: Deriving the word (range) at cursor location
- From: Jay Freedman
- Re: Deriving the word (range) at cursor location
- Prev by Date: Re: Deriving the word (range) at cursor location
- Next by Date: Re: Deriving the word (range) at cursor location
- Previous by thread: Re: Deriving the word (range) at cursor location
- Next by thread: Re: Deriving the word (range) at cursor location
- Index(es):