View Single Post
 
Old 06-24-2012, 02:51 PM
Chayes Chayes is offline Windows XP Office 2003
Advanced Beginner
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default Selecting text between two key phrases

Hi

I'm using this code to select text between two key phrases ;

Code:
Dim myrng As Range, endrng As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
  Do While .Execute(findText:="MORE INFO ABOUT THE ITEM ", MatchCase:=True, Forward:=True, Wrap:=wdFindStop) = True
    Set myrng = Selection.Range
  Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
  Do While .Execute(findText:="ITEM NUM : ", MatchCase:=True, Forward:=True, Wrap:=wdFindStop) = True
    Set endrng = Selection.Range
  Loop
End With
myrng.End = endrng.End
myrng.Select
Unfortunately this only selects the first occurence and no others in the text. If there is more than one occurence the code selection spans whole tract of text.

I'd like it to select all of the specific occurences in the passage. If there are several times when the two inputs phrases can be found then it should find and select all occurences discretely.

Can someone advise with some modification or alternative code?

Grateful for any help.

Last edited by macropod; 06-24-2012 at 04:29 PM. Reason: Added code tags & formatting
Reply With Quote