Removing double empty lines (two 0x0a 0x0a in a row)

MACRO: REMOVEEMPTYLINES

PURPOSE: To remove double empty lines (two 0x0a 0x0a in a row)

WHY: When converting from mac/unix/dos text file formats some programs stuff up by making double lines which is annoying

HOW: Just mark your area and run the macro

Sub RemEmptyLines()
 Dim comp
 str = ActiveDocument.Selection.Text
 str1 = ""
 comp = vbLf + vbLf
 comp2 = vbLf + vbLf
 i = 1
 Do While (i < Len(str)+1)
 Do While Mid(str, i, 2) = comp
 i = i + 1
 Loop
 str1 = str1 + Mid(str, i, 1)
 i = i + 1
 Loop
 ActiveDocument.Selection.Text = str1
End Sub

Date Last Updated: February 1, 1999



Comments

  • nice example

    Posted by Legacy on 07/06/2002 12:00am

    Originally posted by: kirankumar


    Nice, but i want paragraph funcations any examples is there please infoam my mail id

    my problem is starting of document to space finishing of the file two spaces.


    please sir
    your friend

    Reply
  • Nice, but destroys the nice formatting

    Posted by Legacy on 05/11/1999 12:00am

    Originally posted by: Yonat

    This is really useful, but it deletes double new lines even 
    
    when you don't want too (ie, when the original file
    containes empty lines).

    Here is my own version, which just deletes every second line:

    Sub DelEvenLines()
    'DESCRIPTION: Delete all even lines in a file. Useful for files where MSDev turned every LF to an empty line.
    ActiveDocument.Selection.StartOfDocument
    currLine = 1
    prevLine = 0
    Do While currLine > prevLine
    ActiveDocument.Selection.LineDown
    If ActiveDocument.Selection.Text = "" Then
    ActiveDocument.Selection.Delete
    End If
    prevLine = currLine
    currLine = ActiveDocument.Selection.CurrentLine
    Loop
    End Sub

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds