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 / October 2005

Tip: Looking for answers? Try searching our database.

Text beyond cursor and highlight words

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NG - 06 Oct 2005 18:24 GMT
Hi All

I want to read all the text after the cursor location.

I also want to read and highlight one word at a time.

Can anyone please help me with a code sample.

Also can anyone pls direct me to some basic tutorials that teach the above
things.

Thanks
NG
Helmut Weber - 07 Oct 2005 09:10 GMT
Hi,

like this:

Sub Test8976()

' puts what is after the insertion point
' into a variable, but there are limitations
Dim sTmp As String ' a temporary string
Dim rTmp As Range  ' a temporary range
Set rTmp = ActiveDocument.Range
rTmp.start = Selection.start
sTmp = rTmp.Text
MsgBox sTmp

End Sub

Sub Test8977()

Dim sTmp As String ' a temporary string
sTmp = Selection.Words(1).Text
MsgBox sTmp
Selection.Words(1).HighlightColorIndex = wdYellow

End Sub

Can't think of anything else right now:
http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Tony Jollans - 07 Oct 2005 11:24 GMT
Forgive me for being ignorant here but what are you trying to achieve?

Read and highlight each word. As it makes no sense for code to whizz through
all the words highlighting one at a time except perhaps as a bit of light
entertainment you must be looking for something interactive.

To select the next word takes two key combinations: Ctrl+Right Arrow
followed by Ctrl+Shift+Right Arrow

I just recorded this and got

Sub Macro3()
'
' Macro3 Macro
' Macro recorded 07/10/2005 by Tony
'
   Selection.MoveRight Unit:=wdWord, Count:=1
   Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
End Sub

Assign that to a hotkey combination and away you go.

Or do you really mean *highlight*?

You could incorporate highlighting into the code like this perhaps:

Sub Macro3()
'
' Macro3 Macro
' Macro recorded 07/10/2005 by Tony
'
   Selection.Range.HighlightColorIndex = wdAuto
   Selection.MoveRight Unit:=wdWord, Count:=1
   Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
   Selection.Range.HighlightColorIndex = wdYellow
End Sub

but it doesn't do much unless you want to leave some words highlighted for
later which you could do by pressing the right arrow before the hotkey for
the next invocation of the macro.

If that doesn't help, tell me more.

--
Enjoy,
Tony

> Hi All
>
[quoted text clipped - 9 lines]
> Thanks
> NG
 
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.