Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Blank Pages macro 1

Status
Not open for further replies.

PBREP

MIS
Mar 14, 2003
75
0
0
US
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
p.Range.Select
ActiveDocument.Application.Selection.Delete
End If
Next p
End If
Next s
 
Hi,

Try looping through the Sections in reverse using another index. This way you could loop...
Code:
For i2 = ActiveDocument.Sections.Count to 2 Step -1
...and you don’t encounter the Index at all.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thanks Skip for the quick reply, your suggestion worked. ~PM
 
Great!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top