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
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