Re: Replacing a whole paragraph

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Dear Newzad,



Assume your text looks like this:



#1 The cat sat on the mat. The cat sat on the mat. The cat sat on the mat.
The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The
cat sat on the mat. The cat sat on the mat.¶



#2 Now is the time for all good men to attend the next party. Now is the
time for all good men to attend the next party. Now is the time for all good
men to attend the next party. Now is the time for all good men to attend the
next party. Now is the time for all good men to attend the next party. Now
is the time for all good men to attend the next party. Now is the time for
all good men to attend the next party. Now is the time for all good men to
attend the next party. Now is the time for all good men to attend the next
party. Now is the time for all good men to attend the next party. Now is the
time for all good men to attend the next party. Now is the time for all good
men to attend the next party. Now is the time for all good men to attend the
next party. ¶



#3 The cat sat on the mat. The cat sat on the mat. The cat sat on the mat.
The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The
cat sat on the mat. The cat sat on the mat



1 Start macro recording, name, assign shortcut keys.

2 Search for #2 and press Esc

3 Right arrow once.

4 Search for ¶¶ [use ^p^p in search window] and press Esc

5. Right arrow once (places cursor to left of "#3".)

6, Shift-ctrl-up twice.

7 Delete

8. Stop macro recording



This should allow you to delete #2 para no matter how long it is, provided
it always ends with two carriage returns. If more than two, alter step 2
appropriately.



Should get a macro that looks like this:



Sub Junk()

'

' Junk Macro

' Macro recorded 6/1/2005 by RO

'

Selection.Find.ClearFormatting

With Selection.Find

.Text = "#2"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

Selection.MoveRight Unit:=wdCharacter, Count:=1

Selection.Find.ClearFormatting

With Selection.Find

.Text = "^p^p"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

Selection.MoveRight Unit:=wdCharacter, Count:=1

Selection.MoveUp Unit:=wdParagraph, Count:=2, Extend:=wdExtend

Selection.Delete Unit:=wdCharacter, Count:=1

End Sub



Hope this helps.



Richard



"Newzad Hirori" <nawzads@xxxxxxxxxxx> wrote in message
news:kNjne.26141$d5.176597@xxxxxxxxxxxxxxxxxx
> Dear Richard,
>
> The para. do begin with a constant #02 but its end is only determined by
> the para. sign. How many characters and blanks follow #02 is not fixed.
> What shall I do?
>
>
> "mpt" <mpt@xxxxxxxxx> skrev i meddelandet
> news:Ot6ne.22755$PS3.13349@xxxxxxxxxxxx
>> Newzad, if para. #2 does indeed start with "#2" (and the content is
>> uniform, say only one period at the end of the paragraph) I would create
>> a macro (alt-t-m-r) called "junk" and assign it to keyboard shortcut
>> ctrl-j.
>>
>> Then I would have it do the following:
>>
>> 1. search for the unique beginning to each paragraph you want to delete.
>> ("#2"?)
>> 2. escape
>> 3. search for period at end of paragraph.
>> 4. press right arrow until your cursor is to the left of "#3".
>> 5. press ctrl-shift and up arrow until para. #2 is highlighted, along
>> with its trailing carriage returns.
>> 6. delete
>> 7. stop macro recording.
>>
>> Now go to top of your document and press ctrl-j until all your deletions
>> are made.
>>
>> If the formatting of your #2 para. is not uniform or if there is not a
>> unique character combination at the beginning of the para, you're hosed
>> pretty much. In this event, you could perhaps search for every third
>> combination of two carriage returns (^p^p) and do something like I've
>> suggested.
>>
>> I hope this is the germ of a solution for you.
>>
>> Richard
>>
>> "Newzad Hirori" <nawzads@xxxxxxxxxxx> wrote in message
>> news:CVWme.26019$d5.176425@xxxxxxxxxxxxxxxxxx
>>> Dear all,
>>>
>>> Is there a way to find and replace a whole paragraph in Word? My
>>> document consists of many paragraphs like these:
>>>
>>> #01 article
>>>
>>> #02 author
>>>
>>> #03 source.
>>>
>>>
>>>
>>> What I want is to delete all occurrences of #02 in the document.
>>>
>>>
>>>
>>> - Newzad
>>>
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: The Doctrine of Feline Sedentation.
    ... Sat on a Mat" in World Religions. ... > The Doctrine of Feline Sedentation. ... > course mean that the cat literally sat on the mat. ... > floor, ...
    (rec.pets.cats.anecdotes)
  • Re: The Doctrine of Feline Sedentation.
    ... The Doctrine of Feline Sedentation. ... How would Christians deal with "The cat sat on the mat" if it appeared ...
    (rec.pets.cats.anecdotes)
  • The Doctrine of Feline Sedentation.
    ... The Doctrine of Feline Sedentation. ... How would Christians deal with "The cat sat on the mat" if it appeared ...
    (rec.pets.cats.anecdotes)
  • Re: The Cats and the Mats
    ... The Doctrine of Feline Sedentation. ... How would Christians deal with "The cat sat on the mat" if it appeared ...
    (rec.pets.cats.anecdotes)
  • Re: The Doctrine of Feline Sedentation.
    ... The Doctrine of Feline Sedentation. ... How would Christians deal with "The cat sat on the mat" if it appeared ... floor, ...
    (rec.pets.cats.anecdotes)