Selection Points

A

Andy Levy

Hi

I want my vbscript to automatically select text between two points. For
example i want all text between the word "start" and "finish" to be selected
on the page.

Hope you can help

Thanks

AL
 
C

Cindy M -WordMVP-

Hi Andy,
I want my vbscript to automatically select text between two points. For
example i want all text between the word "start" and "finish" to be selected
on the page.
Try it with something along these lines

Sub SelectText()
Dim rng1 As Word.Range, rng2 As Word.Range

Set rng1 = ActiveDocument.Range
Set rng2 = rng1.Duplicate

With rng1.Find
.ClearFormatting
.Text = "start"
.Execute
If .Found Then
With rng2.Find
.Text = "finish"
.Execute
If .Found Then
rng1.Collapse wdCollapseEnd
rng1.End = rng2.Start
rng1.Select
End If
End With
End If
End With
End Sub


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
K

Klaus Linke

Hi Andy,

With a wildcard search, you'd get away with a simple "Find":

Sub SelectText()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.ClearFormatting
.Text = "start*finish"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute
End With
End Sub

Greetings,
Klaus
 
C

Cindy M -WordMVP-

Hi Klaus,
With a wildcard search, you'd get away with a simple "Find":
Unless, taking the question literally (which I did), you don't
want to include "Start" and "find" in the selection...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
A

Andy Levy

Thank you very much for all your help. You have all found great solutions
to my problem.
Andy
 

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