Using find and replace to delete paragraph

R

Robert

I can record a macro to find a certain word in a
paragraph, and I can delete the word, but what code do you
use to delete the whole paragraph where the word is
located? Thanks.
 
J

Jay Freedman

Robert said:
I can record a macro to find a certain word in a
paragraph, and I can delete the word, but what code do you
use to delete the whole paragraph where the word is
located? Thanks.

Hi, Robert,

When you find the word with a Range object or the Selection, then the
paragraph that contains the word is .Paragraphs(1), like this:

Sub ZapPara()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindStop
.Text = "quicker" ' substitute your word

Do While .Execute
oRg.Paragraphs(1).Range.Delete
Loop
End With
End Sub
 

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