Macro to select multiple sentences

A

Alfred

I use the following macro in VB6 - Word 2003 - Windows XP:

Sub SelectSentence()
Selection.Sentences(1).Select
End Sub

I assigned the shortcut Alt+R to this macro. Now I want to be able to
select multiple sentences, but I cannot figure out how to do this.

What I would like to do the macro is:
1) select the sentence in which the cursor is
2) if I keep Alt pressed and hit the R-key again, the macro will keep
the first sentence selected and extend the selection with the next
sentence

Any help appreciated.
Alfred
 
H

Helmut Weber

Hi Alfred,

there maybe other and simpler ways, but at least for a simple text
this seems to work.

Sub SelectSentence()
Dim rTmp As Range
Dim x As Long
If selection.Type = wdSelectionIP Then
selection.Sentences(1).Select
Exit Sub
End If
Set rTmp = selection.Range
x = rTmp.start
selection.Sentences.Last.Next.Select
selection.Sentences(1).Select
selection.start = x
End Sub


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
A

Alfred

Your code works like a charm and does exactly what I wanted to
achieve.
I would never ever have found this out myself, though I really
tried-:)
Thank you very much, Helmut!
Alfred
 

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