Deleting a line in WORD when a certain string is found

C

Charles

How can I delete a line(complete paragraph) in WORD when I find a certain
string? Lets say the string is somehere within the paragraph?

Thank You Charles BinzHow
 
J

Jezebel

With 'Use wildcards' checked,

Search for: ^013[!^013]@<WORD>[!^013]@^013
Replace with: ^013

Two issues: 1) this assumes that the string is WITHIN the paragraph, not at
either end. Remove the leading and trailing [!^013]@ to find instances at
the start and end of the paragraph respectively

2) It assumes that your string is a discrete word. Remove the < and > if you
also want to find the string within a word.
 
H

Helmut Weber

Hi Charles,

just one of many ways:

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

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
Top