Deleting text based on a search

H

Hank Youngerman

I would like to define a keystroke or combination that would search for
a string and delete all the text from the present cursor position to
that position. Any suggestions?

Thanks in advance.
 
C

Cindy M.

Hi Hank,
I would like to define a keystroke or combination that would search for
a string and delete all the text from the present cursor position to
that position. Any suggestions?
Create two range variables. Set one to the current position
Set rngStart = Selection.Range

Set the other to the duplicate of the first, then use it for the Find
property
Set rngFind = rngStart.Duplicate
With rngFind.Find
'Find settings come here
'Use the macro recorder to determine them
End With

After a successful Find.Execute the rngFind will contain the target text.
The original range should be extended to the starting point of rngFind,
then you can delete it:
rngStart.End = rngFind.Start
rng.Delete

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

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

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