Macro to eliminate mutiple blank lines.

W

WCyrek

Hi, just wondering if anyone has made one already (Please
dont waste your time writing it unless you have it), I
need a macro that will go through a document and spot
places where there is more than one blank line between
lines with text and leave only one line. I'm looking for
a simple recursive function. I can write a big function
to do it but I think there is a simpler way I'm
unfamiliar with. NOTE: I tried lookign for consecutive
line breaks replacing them with one line break but that
didn't really work.
 
H

Helmut Weber

Hi,
what happened, when you tried to replace consecutive
line breaks with one line break? How did you try?
What means "didn't really work"?
Did it work every now and then?
Could you give us some sample text and your code?
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
J

Joost Verdaasdonk

-----Original Message-----
Well the thing I did try, since I didn't have time to
code anything, usign the repalce command I put in "^l^l"
in the find window, which is the code for manual line
break I believe, and I put in "^l" in teh replace with
window. However becuase the characters are on different
lines, my theory anyway, it couldnt find two consecutive
line breaks. Another theory of mine was that becuase the
file I was working with was downloaded from a database in
a RTF format, perhaps it was a different kind of line
break, non-manual if such exists, so looking for a manual
line break might not be the way to go. So in any case it
didn't do anything, no replacements were made.

I know I could code soemthign that goes line by line
analyzin whats in the line and if its essentually nothing
it can record two consecutive events of nothing found and
delete one line. But as I said I hardly have the time at
the moment for a side project.



.

Hi,

In a module:

Option Explicit

Public Function test() As Boolean
Dim x As Variant
Dim i As Integer

With Selection
.HomeKey Unit:=wdStory

For Each x In ActiveDocument.Paragraphs
If Len(x) = 1 And i = 1 Then
.TypeBackspace
ElseIf Len(x) = 1 Then
i = 1
Else
i = 0
End If
.MoveDown , 1
Next
End With
End Function

Sub Enters()
Call test
End Sub

Close the VBE en press ALT+F8
Run ENTERS

Have Fun!

Joost Verdaasdonk
The Netherlands
 
W

WCyrek

Works perfectly. I gave you credit in the comments incase
I stick it in a userform later. So no need to sue :)
 
J

Joost Verdaasdonk

Hahahaha, :D

Feel free to use it as you please!

Have fun ;-)

Joost Verdaasdonk
 

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