How to Select Pragraph By Defining Range

A

AbdulRehman

For Example

Starting Point is A.

A. hello Friend
B. by
C. First
D. Great

Answer


and than Go to Answer

Select the lines between
A. TO Answer but not answer
 
H

Helmut Weber

Hi AbdulRehman,

like this, some finetuning and error handling
might be recommendable.

Sub Fromto()
Dim lPos As Long
Dim Str1 As String
Dim Str2 As String
Dim rTmp As Range

Set rTmp = ActiveDocument.Range

Str1 = "A"
Str2 = "Answer"
With rTmp.Find
.Text = Str1
.MatchCase = True
If .Execute Then
rTmp.Select ' for testing
lPos = rTmp.Start
rTmp.End = ActiveDocument.Range.End
Else
Exit Sub
End If
.Text = Str2
If .Execute Then
rTmp.End = rTmp.End - Len(Str2)
rTmp.Start = lPos
rTmp.Select
Else
Exit Sub
End If
End With
End Sub

There might be other ways,
but the hard way will often be more versatile in the end.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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