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

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 1, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.