Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

how to select range of text to delete?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RNEELY - 27 Jan 2005 21:21 GMT
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.

Signature

Regards,
-Ron

Greg Maxey - 27 Jan 2005 22:34 GMT
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.
Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Given a document with the following text:
>   The quick brown fox jumped high.
[quoted text clipped - 34 lines]
>
> Please help.  I am really stuck.
RNEELY - 27 Jan 2005 23:33 GMT
Thanks Greg.  That is a cool feature.

> You don't need a macro.
>
[quoted text clipped - 42 lines]
> >
> > Please help.  I am really stuck.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.