Re: Deriving the word (range) at cursor location
- From: Jay Freedman <jay.freedman@xxxxxxxxxxx>
- Date: Sun, 03 Dec 2006 15:27:21 -0500
Hi MAB,
The background color and the highlight color are two completely
separate and independent settings. If you set the color with the
Highlight button, then your macro must change the range's
..HighlightColorIndex value instead of its .BackgroundPatternColor
value. (This sort of thing is where you really need an intimate
knowledge of Word's feature set -- otherwise it will drive you nuts!)
So change the line
oRg.Shading.BackgroundPatternColor = wdColorAutomatic
to this:
oRg.HighlightColorIndex = wdAuto
--
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.
On Sun, 3 Dec 2006 11:45:00 -0800, MAB <MAB@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
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.
- 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
- From: MAB
- 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):
Loading