Solved

Macro to delete empty paragraph marks is also deleting section breaks

Posted on 2004-04-30
3
502 Views
Last Modified: 2012-05-04
I am trying to get rid of extra paragraph marks in a Word document. I have a macro that will delete all the empty paragraph marks in the document, but the problem is that it also deletes section breaks if they are right above the empty paragraph mark.

Is there a way to change the macro so that only the paragraph marks are deleted, not the section breaks above them?

Here's my code:

' Delete all empty paragraphs
For Each currPara In ActiveDocument.Paragraphs
    If Len(Trim$(currPara.Range.Text)) = 1 Then
        currPara.Range.Delete
    End If
Next
0
Comment
Question by:sehenkel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Tommy Kinard earned 300 total points
ID: 10960805
Hi sehenkel,

For Each currPara In ActiveDocument.Paragraphs
    If Len(Trim$(currPara.Range.Text)) = 1 Then
        currPara.Delete Unit:=wdCharacter, Count:=1
    End If
Next

Let me know if more help is required
dragontooth

0
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 11259655
The code I posted worked for me. No clue if it answered the question.

dragontooth

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question