Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

How to remove every line of text that starts with xxxxxxxxx

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marty Christion - 27 Dec 2006 01:07 GMT
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?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.