how to remove empty paragraphs

F

Flip Kalee

Hi group,
Some time ago Jonathan West helped me out to do some layout on imported
texts (this is still working great, Jonathan!)
This is how a certain style is activated depending on a paragraphs length

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Content.Paragraphs
If Len(oPara.Range.Text) = 78 Then
oPara.Style = ("STYLE1")
End If
If Len(oPara.Range.Text) = 63 Then
oPara.Style = ("STYLE2")
End If
Next oPara

My problem:
I want to delete every paragraph shorter then three chars including empty
ones.
Can this be done with an extra If -- End If loop

If Len(oPara.Range.Text) < 3 Then
...
End If

Or do I need something else here?
We are on Office97 and 2000

Flip Kalee
 
D

Doug Robbins - Word MVP

Hi Flip,

Yes it could be done that way, but remember that the paragraph mark will be
counted in the Len()

Thus a paragraph taht cotnains 2 letters will have a length of 3. So if you
want to delete a paragraph containing 2 letters you have to use

For Each apara In ActiveDocument.Paragraphs
If Len(apara.Range) < 4 Then apara.Range.Delete
Next apara

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
F

Flip Kalee

Hi Doug,
Thanks for helping and yes, I did notice the LEN includes the pragraph mark
(after a while :) )
One more question:
How can i identify an aPara with spaces only? I want to remove those also.

Flip
 
D

Doug Robbins - Word MVP

Hi Flip,

The best way to do that is to use a wildcard replace with

(^13)([ ]{1,}^13)

in the find what box and

\1

in the replace with box.

You can record that action if you want to use it in a macro.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
F

Flip Kalee

Hi Doug,
Great
Thanks again
Flip

Doug Robbins - Word MVP said:
Hi Flip,

The best way to do that is to use a wildcard replace with

(^13)([ ]{1,}^13)

in the find what box and

\1

in the replace with box.

You can record that action if you want to use it in a macro.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Flip Kalee said:
Hi Doug,
Thanks for helping and yes, I did notice the LEN includes the pragraph mark
(after a while :) )
One more question:
How can i identify an aPara with spaces only? I want to remove those also.

Flip

will
be if
you
 

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