Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

determine last word selected or changed possition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
filo666 - 27 Feb 2008 15:25 GMT
Hello, Is there a way to set a variable with the possition of the last word
changed???
last word selected???

TIA
Julian - 27 Feb 2008 16:53 GMT
Yes, I have done something similar myself but the functionality you seek is
embedded deep in code that doesn't match your specifics so I shan't dump the
whole lot here... however here are some pointers...

1. You need to use events, specifically the WindowSelectionChange event,
which means creating a Class module (e.g. "eventClassModule") and declaring
Public WithEvents App As Word.Application in it, and in a code module
initialising events declare e.g. "Public myWord As New eventClassModule" and
then somewhere put e.g. Set myWord.App = Word.Application
2. On selection change (i.e. in the class module created in step 1, in sub
App_WindowSelectionChange...) you then need to determine whether you are in
the same word or not, and if that word has changed each time the selection
changes
2a. Assuming, for simplicity that the selection is a Selection point at the
time of change, copy the selection range and expand it to the encompassing
word; record the range in a range variable.
2b. The next time the selection changes compare the location (perhaps
linenumber and distance from beginning of the line) of the current word with
that of the previous word... then look back at the previous range that
contained the "word" and see if the text has changed...

Finally, be aware that as you type, the selection does not change - only
clicks and navigation keys and goto and search etc. actually move the
selection...

Someone more virtuous might post you specific code, but if you feel up to
doing it yourself I hope the above helps... at least I hope it's more of a
help than a hindrance!

Julian

> Hello, Is there a way to set a variable with the possition of the last
> word
> changed???
> last word selected???
>
> TIA

Signature

Julian I-Do-Stuff

Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com

Tony Jollans - 27 Feb 2008 19:04 GMT
Look at the builtin bookmark "\PrevSel1".

Signature

Enjoy,
Tony

> Hello, Is there a way to set a variable with the possition of the last
> word
> changed???
> last word selected???
>
> TIA
fumei - 27 Feb 2008 19:44 GMT
You need to define your requirements more.  Define "last word".

Say you have (as text):

"the quick brown fox
yadda yadda"

Say you move the selection to the "w" of "brown", and type "greeeee"

"the quick browgreeeeen fox
yadda yadda"

Now say you move the Selection (cursor) to the second "yadda", and run:

Selection.GoTo what:=wdGoToBookmark, Name:="\PrevSel1"

the Selection (cursor) will move to the last "e" of the "greeeee" you typed.

Now, say you actually select "quick"...but you do NOT do any action.  You
just selected it....then changed your mind, and moved the cursor to that
second yadda.  Remember, you DID select "quick".

Selection.GoTo what:=wdGoToBookmark, Name:="\PrevSel1"

will STILL go the the last "e" of the "greeeee" you typed.  Even though the
last selection was "quick".  If you DO something with "quick", then PrevSel1
will go back to it.  If you just select it, but do nothing, it won't.

What I am saying is you have to clearly define exactly what it is you want to
do.

Last word changed?  Yes, you could use PrevSel1 and then expand the Selection
to the whole word - if it was not the whole word in the first place.  if the
previous Selection WAS the whole word, then PrevSel1 would get the whole word.
But typing is not a whole word.  PrevSel1 goes to the last location as a
single character.

>Look at the builtin bookmark "\PrevSel1".
>
[quoted text clipped - 4 lines]
>>
>> TIA
fumei - 27 Feb 2008 19:47 GMT
I also want to emphasize what Julian wrote regarding using events:

"be aware that as you type, the selection does not change - only
clicks and navigation keys and goto and search etc. actually move the
selection..."

>You need to define your requirements more.  Define "last word".
>
[quoted text clipped - 38 lines]
>>>
>>> TIA
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.