How do I delete all non matching lines in a word file?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a large file that I would like to cull out all the lines that do not
contain a tag/header. How do I do this?
 
Carl,

If the tag/header is in a Heading style (i.e., Heading 1), you could
use a macro like:

Sub DeleteText()

Dim oStyle As Style
Dim oPara As Paragraph

For Each oPara In ActiveDocument.Paragraphs
Set oStyle = oPara.Style
If oStyle <> "Heading 1" Then
oPara.Range.Delete

End If
Next oPara
End Sub

If that is not the case then you may be able to use a series of find
and replace.

Say you have

XX-Parts:
blah, blah,
XX-Labor
blah, blah
etc.

Your heading "Tag" is XX-

Edit>Replace>More Use Wildcards

Type (XX-)(*)^13 in the find what field
Click in the replace with field then click the format button and click
highlight.
Your tagged headers should appear as highlighted text.

Now click in the find what field, clear the contents, uncheck the Use
Wildcards. Click in the replace with field and then press the no
format button. Go back to the Find what field and click format
hightlight twice. Format "Not Highlight" should appear beneath the
find what window. Press replace all

Now all that is left is highlighted Header text.

Select all (CTRL+a) and use the highlighting tool (located on the
reviewing toolbar) to remove highlighting
 
Back
Top