Selecting just one word in document

J

Jim

When I use:

Selection.Words.Count

with nothing selected I get Selection.Words.Count =1

I get the same result when I actually select just one word (which I
expected).

Likewise if I use Selection.Words.First, I get then next word after cursor.

How do I know if the user REALLY just selected one word?
thanks
 
J

Jezebel

You need to examine what they've selected. You might find the LIKE operator
helpful.

The problem is that 'word' is actually quite hard to define. The definition
used for the Words collection is something like a) any sequence of these
characters [a-zA-Z0-9'] delimited by any characters not in that set, plus b)
any characters other than space, with sequences of the same character
treated as one word. I suspect that this definition was arrived at to
facilitate functions like Find and Replace. It's obviously not very helpful
for strictly lexical purposes.
 
J

Jean-Guy Marcil

Jim was telling us:
Jim nous racontait que :
When I use:

Selection.Words.Count

with nothing selected I get Selection.Words.Count =1

I get the same result when I actually select just one word (which I
expected).

Likewise if I use Selection.Words.First, I get then next word after
cursor.
How do I know if the user REALLY just selected one word?
thanks

With Selection.Range
If .Start = .End Then
MsgBox "Nothing is currently selected"
Else
MsgBox "Something is actually selected"
End If
End With

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jim

- thanks - merci.

Jean-Guy Marcil said:
Jim was telling us:
Jim nous racontait que :


With Selection.Range
If .Start = .End Then
MsgBox "Nothing is currently selected"
Else
MsgBox "Something is actually selected"
End If
End With

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Cindy M.

Hi Jean-Guy,
With Selection.Range
If .Start = .End Then
MsgBox "Nothing is currently selected"
Else
MsgBox "Something is actually selected"
End If
End With
How about Selection.Type?
If Selection.Type = wdSelectionIP Then

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun
17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
J

Jean-Guy Marcil

Cindy M. was telling us:
Cindy M. nous racontait que :
Hi Jean-Guy,

How about Selection.Type?
If Selection.Type = wdSelectionIP Then

Yes!

I was actually looking for that as I remembered that there was a property
that could check if the selection was an insertion point or not. I thought
it was something like "InsertionPoint"... Obviously I did not find it, so I
came up with a hack instead!

Thanks!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top