Need CODE to delete all lines from a huge word document, that doesn't

J

John

Hi

Would be extremely grateful if someone could help me write the code
for this!

Thanks
J
 
G

Graham Mayor

'Line' is a vague concept in Word, but assuming you mean paragraph i.e. a
'line' ending with ¶ then

Sub DeleteQuestions()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If LCase(oPara.Range.Words(1)) = "question " Then
oPara.Range.Delete
End If
Next oPara
End Sub

http://www.gmayor.com/installing_macro.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

On further reflection, as the character following Question is not stated,
use instead

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If Trim(LCase(oPara.Range.Words(1))) = "question" Then
oPara.Range.Delete
End If
Next oPara

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
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