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?
Shauna Kelly - 30 Dec 2006 10:17 GMT
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
>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
[quoted text clipped - 3 lines]
> automatically delete these lines, and have a blank line left in their
> place. Is there an easy way to do this?
Doug Robbins - Word MVP - 30 Dec 2006 10:26 GMT
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

Signature
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
>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
[quoted text clipped - 3 lines]
> automatically delete these lines, and have a blank line left in their
> place. Is there an easy way to do this?