Excel and Office RAQ

Getting rid of empty paragraphs in Word

   

Tactical solutions

Research projects

Microsoft Office

Multiple choice guessing

Services

Knowledge measurement audit

Item bank services

Item design course

Products

WaterMarker

iOTA

STASiS

ACiS

CaSelector

CaSCADE

Technical articles

Excel and Office RAQ

Free Excel Add-in

Free PowerPoint Add-in

Contact

Home page

Q: I have a document which contained unwanted paragraph marks.

Essentially what I want to do is to delete every line that contains only spaces and paragraph marks. Note some lines contain no spaces, just para marks, other lines have multiple spaces and then paramarks.

Anyone able to tell me what the find command will be?

A: This code will do the job:

  Sub LoseEmptyParas()

 

  Dim p As Paragraph

  Dim myFlag As Boolean

  Dim myString As String

  Dim myNewString As String

 

  For Each p In ActiveDocument.Paragraphs

    myString = p.Range.Text

    myFlag = False

    myNewString = Replace(myString, " ", "")

    If Len(myNewString) > 1 Then myFlag = True

    If myFlag = False Then p.Range.Delete

  Next

 

  End Sub

 

 

Back to other RAQ topics