Determining the word possition

F

filo666

Hello, I would like to:

1) Detemine the word number or possition (something like
wrd=activedocument.selection.words.possition) but of course it does not work.

2) to program this:


If the selected word is "-" and one word before the selected word is a
letter or a number (just a letter or a number) and one word after the
selected word is a space(" ") then ..........

thanks for your help.
 
K

Klaus Linke

Hi,

Sounds like a wildcard search would be simpler for what you're trying to do:
Edit > Find, Check "Match wildcards",
Find what: <[a-zA-Z0-9]\-^32

Likely you can achieve whatever you want to do next with a replacement, or
take it from there.

re 1):
What do you mean with "position"... a Range? The character count from the
beginning of the range up to that word? The word count?
It could be something as simple as Selection.Words(1).Start ... or look at
http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm

re 2):
You could look at "Like" in the VBA help.
The word preceeding the one you have selected would be
Selection.Words(1).Previous.Words(1)

But as suggested above, you might take a step back and describe what your
text looks like and what you want to achieve. Dealing with "words" in the
Word object model would probably be the slowest and most cumbersome way to
go about it.

one word after the selected word is a space(" ")

A space is never regarded as a word by itself... Spaces belong to the word
preceeding it.

Regards,
Klaus
 

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