Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Delete Blank Pages macro

Delete Blank Pages macro

Delete Blank Pages macro

Hello VBA Programmers,
I have the following macro which deletes blank paragraphs from a Word document (e.g. user can see blank pages in Print Preview). I loop through all sections in the document, and if the section does not contain the table of contents, then I delete the blank paragraphs in that section. The Long variable i is defined elsewhere and corresponds to the index of the Section that contains the table of contents.

My problem is that when looping through ActiveDocument.Sections, s.Index is always 1. If I take out the ActiveDocument.Application.Selection.Delete line, then s.Index increases as expected. What am I doing wrong? Thank you, ~PM

Dim s As Section
Dim p As Paragraph

For Each s In ActiveDocument.Sections
If i <> s.Index Then
For Each p In s.Range.Paragraphs
If Len(p.Range.Text) <= 1 Then
End If
Next p
End If
Next s

RE: Delete Blank Pages macro


Try looping through the Sections in reverse using another index. This way you could loop...


For i2 = ActiveDocument.Sections.Count to 2 Step -1 
...and you don’t encounter the Index at all.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Delete Blank Pages macro

Thanks Skip for the quick reply, your suggestion worked. ~PM

RE: Delete Blank Pages macro



glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close