how to select range of text to delete?

R

RNEELY

Given a document with the following text:
The quick brown fox jumped high.
There is a cat over the lazy dog.
The quick brown fox jumped.
There is a bird over the lazy dog.

How can I write a macro to delete the text between ‘jumped’ and ‘over’ so
the document ends up like:
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.

The following macro finds the end of ‘jumped’:
Sub FindFoxyJump()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "jumped"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

Specifically how can one begin a selection from that location, and extend it
to the beginning of ‘over’? While it is simple to select text by moving the
cursor with
Selection.MoveDown Unit:=wdLine, Count:=2, Extend:=wdExtend
There seems to be no such Extend:=wdExtend argument for
Selection.Find.Execute.

Please help. I am really stuck.
 
G

Greg Maxey

You don't need a macro.

Edit Find>Replace>More>Use Wildcards
Type (jumped)space<high*bird>space(over) in the find what field

Type \1space\2 in the replace with field and press replace all

Note replace "space" with a single space.
 
R

RNEELY

Thanks Greg. That is a cool feature.


Greg Maxey said:
You don't need a macro.

Edit Find>Replace>More>Use Wildcards
Type (jumped)space<high*bird>space(over) in the find what field

Type \1space\2 in the replace with field and press replace all

Note replace "space" with a single space.
 

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