Find text in line then delete line

S

Stu

I posted this question in "General Word" but I think it is a programming
question. Could someone give me a code snippet that would:
1) find a word/phrase in a document
2) select the line in which the word/phrase is found
3) delete the line in which the word/phrase is found
4) repeat to end of doc.
 
G

Greg Maxey

Stu,

The problem you might have is that a Word document is not made up of lines
and pages. A Word document is made up of characters, words, sentences,
paragraphs, and sections.

If each "line" containing the desired text is an independent paragraph then
you could use something like this:

Sub ScratchMaco()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "whatever your text or phrase is"
While .Execute
oRng.Paragraphs(1).Range.Delete
Wend
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