Automate new paragraph

P

Pete

Can you tell me the 'Find' and 'Replace' (macro) coding which would enable me
to Find the word 'Record' and Replace it with the insertion of an empty line
above the word 'Record'? I regularly go through long documents where it is
not clear where individual records begin. A new paragraph for each would be
very helpful. Many thanks.
 
T

Tony Jollans

You should not add empty paragraphs simply to make space. Define a style
with as much 'space before' as you want, then make all 'Record' paragraphs
into that style.

With Find and Replace (Ctrl+H) ...
Find what: Record
Click in Replace with Box
(Click on more if need be)
Click on Format
Select Style
Choose your new Style
Hit Replace All

This will add space to all paragraphs containing the word "Record". If you
want to only do it to paragaraphs containing nothing else, look for
"Record^p" instead of just "Record"
 
H

Helmut Weber

Hi Pete,
Can you tell me the 'Find' and 'Replace' (macro) coding which would enable me
to Find the word 'Record' and Replace it with the insertion of an empty line
above the word 'Record'?

I'am assuming, that "Record" is found
exclusively in the first line of a paragraph.
If so, have a look at that one:

Sub Testccc()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "Record"
.MatchWholeWord = True
While .Execute
If rDcm.Paragraphs(1).Previous.Range <> Chr(13) Then
rDcm.Paragraphs(1).Range.InsertBefore Chr(13)
End If
Wend
End With
End Sub
 
H

Helmut Weber

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
P

Pete

Works a treat. Thanks

Helmut Weber said:
Hi Pete,


I'am assuming, that "Record" is found
exclusively in the first line of a paragraph.
If so, have a look at that one:

Sub Testccc()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "Record"
.MatchWholeWord = True
While .Execute
If rDcm.Paragraphs(1).Previous.Range <> Chr(13) Then
rDcm.Paragraphs(1).Range.InsertBefore Chr(13)
End If
Wend
End With
End Sub
 

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