Removing the top 2 lines of each page on a document

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
 
J

Jean-Guy Marcil

USAFA was telling us:
USAFA nous racontait que :
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.

"it's not working" is not very helpful. I can guess by looking at the code
what might be wrong, bit if you state it explicitly, then we can often solve
problems faster because sometimes people have expectations that are wildly
different from the what the code would suggest those are...
If you write what you expect (as you have here) and then tell us what the
result was and how it was not working (which you have not), then it is often
easy to fix just by realigning the expectations with the methods...

How are the pages defined?
Run-on text?
Manual Page Break?
Section Break?
Paragraph formatting?

Do all documents where the macro will be used have their pages defined in a
consistent manner?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top