U
USAFA
I'm trying to put together a macro that goes to the beginning of the document
and deletes the top 2 lines (both extra blank lines needing to be removed),
then moves to the next page and deletes the top 2 lines, and so on until it
reaches the end of the document. Once it reaches the end, I want it to stop.
But I've got a problem, because it's not working. Please assist.
Here's my code so far:
Sub Step3()
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
ActiveDocument.Range(0, 0).Select
Do While .Execute
On Error Resume Next
Selection.Collapse Direction:=wdCollapseStart
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.Delete
Selection.MoveEndUntil Cset:=vbCr, Count:=wdForward
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Range.End = ActiveDocument.Range.End Then
ActiveDocument.Range(0, 0).Select
Exit Sub
End If
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Collapse wdCollapseEnd
Loop
ActiveDocument.Range(0, 0).Select
End Sub
and deletes the top 2 lines (both extra blank lines needing to be removed),
then moves to the next page and deletes the top 2 lines, and so on until it
reaches the end of the document. Once it reaches the end, I want it to stop.
But I've got a problem, because it's not working. Please assist.
Here's my code so far:
Sub Step3()
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
ActiveDocument.Range(0, 0).Select
Do While .Execute
On Error Resume Next
Selection.Collapse Direction:=wdCollapseStart
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.Delete
Selection.MoveEndUntil Cset:=vbCr, Count:=wdForward
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Range.End = ActiveDocument.Range.End Then
ActiveDocument.Range(0, 0).Select
Exit Sub
End If
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Collapse wdCollapseEnd
Loop
ActiveDocument.Range(0, 0).Select
End Sub