Select text between

P

PawelR

Hello Group,
I've problem with selection text.
How select text between "ABC" and "XYZ" where between ABC and XYZ is some
text.

Thx PawelR
 
H

Helmut Weber

Hi Pawel,
how about this one:

Sub Selectbetween(sA$, sB$)
Resetsearch
With Selection
.Collapse
.ExtendMode = False
End With
With Selection.Find
.Text = sA$
If .Execute Then
Selection.Collapse direction:=wdCollapseEnd
.Text = sB$
Selection.ExtendMode = True
If .Execute Then
Selection.MoveEnd Count:=-Len(sB$)
End If
End If
End With
End Sub
'---
Sub test()
Selectbetween "e", "o"
End Sub
'---
Sub Resetsearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
'---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 

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