Writing a macro to delete specific lines from a large Word document

J

John

Hi

I have a large Word document, several hundred pages long.

I would like to do the following

Find each and delete every line that starts "Comments:", "Author:",
"MyRating:".

These are typically the first 3 lines of every page, but it can vary.

I am doing this manually, but am curious to know if it's possible do
it using a macro. My guess is this is too complex to do using a
macro.

Thanks
 
G

Graham Mayor

Dim sText() As String
Dim oRng As Range
Dim i As Long
sText = Split("Comments:,Author:,MyRating:", ",")
For i = 0 To UBound(sText)
Selection.HomeKey wdStory
With Selection.Find
Do While .Execute(findText:=sText(i))
Set oRng = Selection.Paragraphs(1).Range
If InStr(1, oRng, sText(i)) = 1 Then
oRng.Delete
End If
Loop
End With
Next i

should do the trick.
Note that the search is case sensitive

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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