Select a Range of Text Between Two keywords.

B

Brian

I have a word document that has two keywords in it.

I would like to select any text that is between these two keywords.

Is there an easy way to do this in VBA?

Example Doc:

Start:::

This is some text.
More stuff
Hello World

End:::

The code would capture everything between the keywords "Start:::" and
"End:::"

Thanks for the help.
Brian
 
D

Doug Robbins - Word MVP

Use:

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute findText:="Start:::", Forward:=True, Wrap:=wdFindStop
Set myrange = Selection.Range
myrange.End = ActiveDocument.Range.End
myrange.start = myrange.start + 8
myrange.End = myrange.start + InStr(myrange, "End:::") - 1
myrange.Select
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Brian

Tha's it... Thanks,
....don't think I would have come up with that one on my own...

I need to study up on that range object a bit 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