How to find some word and delete 8 lines before it?

A

avkokin

Hello.
How can I find of some word into text, next counting 8 of lines before
it and delete these 8 lines?
Thank you.
 
H

Helmut Weber

Hi Anton,

try that one:

Sub Test699()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "some text"
If .Execute Then
rDcm.Select
' Selection.Bookmarks("\line").Select
' Selection.Collapse
Selection.MoveUp
For x = 1 To 7
Selection.Bookmarks("\line").Select
Selection.Delete
Selection.MoveUp
Next
End If
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
T

Tony Jollans

If your 'lines' are really paragraphs, Helmut's code will probably do fine
but if they are not, then deleting one line could cause others to reflow and
who knows what may happen.
 

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