Hello Octo,
I looked up information from the object browser in Visual Basic for MS
Word and have a few ideas on how you can do what you want. You may
want to follow along...
I started with a blank document and typed...
Now is the time for all good people to come to the aid of their
party.
I selected the words "good people to come" with the mouse, then did
Tools -> Macros -> Visual Basic
in Visual Basic I did
View -> Immediate Window
and then typed into that window
print selection.words.first
which displays the value
good
which shows the first word in the selection. You get the same result
if the cursor is positioned before the word good as well. A few other
commands and results included...
print selection.words.count
4
print selection.words
(error)
then position the cursor before the word good (no text selected)...
print selection.words.count
1
print selection.words.first
good
print selection.words.characters
(error)
print selection.range
good
print selection.range.start
24
So, you can find the character position of the current selection using
this method. I wrote a quick subroutine for testing...
Sub X()
For i = 1 To ActiveDocument.Words.Count
If Selection.Range.Start < ActiveDocument.Words(i).Start Then
j = i
End If
Next i
End Sub
set a breakpoint on j = i and run the macro X. You will find that the
function stops when you find the first word after the start of the
current selection (which may not start at the start of the word...).
This is a pretty ugly solution, but I can't seem to find any better
way to find out "which" word in ActiveDocument.Words that
Selection.Words.Start happens to be. If you want me to dig a little
more, please ask for clarification.
If you want to search some more on your own, with the object browser,
type in the phrase into the second field at the top to get a list of
objects and fields that have that phrase in their name. Use the help
librerally (including examples) to find the items that may be able to
help.
--Maniac |