Replacing a whole paragraph

N

Newzad Hirori

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
 
M

mpt

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
 
N

Newzad Hirori

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?
 
M

mpt

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
 

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