Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word 03 - Find and Replace whole paragraphs

Status
Not open for further replies.

fwild3

Technical User
Dec 5, 2003
11
US
I have a 1600 page Word 03 document with 388 iterations of the same paragraph (an e-mail msg) scattered throughout and needing to be removed. Word Find and Replace won't accept a paragraph as as search criterion. Is there some way to identify an entire paragraph for removal? Many thanks.
 
Hi fwikd3,
Word Find and Replace won't accept a paragraph as as search criterion
It does if you specify it correctly in the Find dialogue box. There si, of course a limit to how much text you can insert into the Find dialogue box. You could work around this by breaking the task down to smaller blocks. Alternatively, you could use a wildcard Find/Replace. For example, a wildcard Find/Replace coded as:
Find = The quick brown fox*^13
Replace = nothing
Will delete all paragraphs starting with the words 'The quick brown fox'.


Cheers
[MS MVP - Word]
 
And depending on how unique you can get for a search string, you could do a search through all paragraphs for that string, and action against that. Taking macropod's quick fox example:
Code:
Sub DeleteTheFox()
Dim oPara As Paragraph
Dim str_ASearch As String
str_ASearch = "quick brown fox"

For Each oPara In ActiveDocument.Paragraphs
   If InStr(oPara.Range.Text, str_ASearch) > 0 Then
       oPara.Range.Delete
   End If
Next
End Sub
This just simply tests each paragraph, to see if it has the string "quick fox" inside it. If it does, it is deleted.


unknown
 
Thank you very much. The wildcard *^13 suggestion worked well except that the message had several hard returns in it and required some manual clean up. The deletions removed several hundred pages from the file. It made me wonder whether a code to search for passages with beginning and ending words might work. Thanks again. Mission accomplished.
 
Hi fwild,
the message had several hard returns in it
All that means is that it spanned multiple paragraphs, in which case, if the breaks are all in the same place, you could have used a Find expression along the lines of:
Find = The quick brown*^13lazy dog*^13


Cheers
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top