get thew word number

F

filo666

Hi, I want to accomplish 2 thinks:

1) something like wordpossition=Activedocument.selection.words.possition
(and the possition of the word in the document is obtained)
of course the command is incorrect.

2) an if structure:

If the selected word is "-" and one word or character before the selected
word is a letter or a number (just letter or number, not "/" or "." or
anything) and one character after the selected word is " " then
...........................
end if

Thanks for your help
 
G

Greg Maxey

Something like this:

Sub Scratchmacro()
Dim oWord As Range
Dim oRng As Range
Set oRng = ActiveDocument.Range
Set oWord = Selection.Words(1)
oRng.End = oWord.End
MsgBox oRng.Words.Count
If oWord.Text = "- " Then
If oWord.Characters.First.Previous Like "[A-Za-z0-9]" Then
MsgBox "Bingo"
End If
End If
End Sub

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://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