How to remove every line of text that starts with xxxxxxxxx

M

Marty Christion

I have a long document that had some minor corruption during conversion.
There are now some lines that need to be removed, and all of them start with
xxxxxxxx.

I'm trying to figure out how to search the entire document and automatically
delete these lines, and have a blank line left in their place. Is there an
easy way to do this?
 
S

Shauna Kelly

Hi Marty

Word has only the haziest notion of what a "line" is. Are these "lines"
actually paragraphs? If so, then the following should work. Make a backup of
your document before you start, just in case.

Option Explicit

Sub RemoveXXXXX()
'Finds paragraphs starting with particular
'text and deletes the contents of the paragraph

'Change the following line to change the
'text to search for
Const csTextToFind As String = "xxxxxxxx"

Dim oPara As Word.Paragraph
Dim rngDelete As Word.Range


For Each oPara In ActiveDocument.Paragraphs
With oPara
If .Range.Text Like csTextToFind & "*" Then
Set rngDelete = oPara.Range
rngDelete.MoveEnd wdCharacter, -1
rngDelete.Delete
End If
End With
Next oPara


End Sub



Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
D

Doug Robbins - Word MVP

Use

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[x]{3,}", MatchWildcards:=True, _
MatchCase:=False, Wrap:=wdFindStop, Forward:=True) = True
Selection.Bookmarks("\line").Range.Text = vbCr
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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