Advanced search and replace.

  • Thread starter Thread starter Piotr
  • Start date Start date
P

Piotr

Hi,
i have a document looking like that:
"this is a line with a word cat
this is a line with a word dog
this is a line with a word dog
this is a line with a word cat
this is a line with a word cat
this is a line with a word dog
this is a line with a word cat"
What i have to do is to delete all the lines containing the word "cat". If
it was only few lines i could just do it manually searching and deleting, but
this document has more than 100 pages, and the lines are not one after
another but they are among other sequences.
Is there any way to automate such process? I thought about using replace
function, but i don't think it's capable.
With regards, Peter
 
Use a macro containing the following code:

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="cat", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Selection.Paragraphs(1).Range.Delete
Loop
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, originally posted via msnews.microsoft.com
 
Back
Top