Find text & Replace entire paragraph

P

Phil Spearman

Hi there,

I wonder if anyone out there could help me?

I need to do a find & replace text in documents via a
macro. The text may appear any number of times in a given
doc but its not just *that* text that needs replacing -
its the entire paragraph .

The pseudo code would look something like this I guess...

Find 'Lorem ipsum dolor sit amet'
If found
select the whole paragraph
replace with Null (or delete text)

.....But I cant seem to translate this into successful VBA
code!

Any help greatly appreciated

Phil
 
H

Helmut Weber

Hi Phil,
Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
Sub test560()
Dim oRng As Range
resetsearch
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "reshaping"
While .Execute
oRng.Paragraphs(1).Range.Delete
Wend
End With
resetsearch
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 

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