selecting text

S

sarah

how do i select text around the selected text so that all the text coloured
in a certain colour is selected.
For example the cursor is placed in the middle of a word and i want all of
that word and all the words around that word that are coloured in the same
colour to be selected.

here is the code i am using to do the same to select an entire word:

With Selection
..Expand wdWord
Do While Right(.Text, 1) = Chr(32)
..MoveLeft Unit:=wdCharacter, count:=1, Extend:=wdExtend
Loop
selWord$ = Trim(.Text)
End With

now i want to select an entire phrase in the same colour

what changes do i have to make
 
H

Helmut Weber

Hi Sarah,

how about this one:

Dim lClr As Long
Dim rTmp As Range
Set rTmp = Selection.Range
lClr = Selection.Font.Color
While rTmp.Previous.Font.Color = lClr
rTmp.start = rTmp.start - 1
' rTmp.Select ' for testing
Wend
While rTmp.Next.Font.Color = lClr
rTmp.End = rTmp.End + 1
' rTmp.Select ' for testing
Wend
rTmp.Select

There may be other, simpler and faster ways.

To make sure beforehand,
that the color isn't black or automatic,
might be a good advice in addition!

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
K

Klaus Linke

There's also Selection.SelectCurrentColor (a relic from WordBasic), but it only selects downwards.

Regards,
Klaus
 
H

Helmut Weber

Hi Klaus,

WordBasic.Selectsimilarformatting

would be another method. Selects all that is similar,
and because of unfinished discontiguous selection,
the selection.text returns only the text immediately
adjacent to the insertion point. I didn't use it,
because it rises a whole bunch of other questions.
Nobody knows better than you. ;-)

Schönen Abend noch (Nice evening)

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
Top