Delete a line if a word is NOT found

J

John Smith

I would like to delete a line if a keyword is not found. Can this
be done? This is to mimic what grep program does, sort of.
 
H

Helmut Weber

Hi John,

in case you are talking about paragraphs, not lines:

Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
If InStr(oPrg.Range.Text, "und") = 0 Then
oPrg.Range.Delete
End If
Next

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

John Smith

Helmut said:
Hi John,

in case you are talking about paragraphs, not lines:

Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
If InStr(oPrg.Range.Text, "und") = 0 Then
oPrg.Range.Delete
End If
Next

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Thanks. You're right. It's indeed paragraphs. Since my paragraphs
are so short, they are literally lines.
 

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