Text beyond cursor and highlight words

N

NG

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
 
H

Helmut Weber

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
 
T

Tony Jollans

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.
 

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