Loop through document

R

Rob

I have a document that I would like to do the following until there are no
more pages to perform this action:

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=10, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

How do I create a loop in this circumstance?

Any help would be appreciated.

Rob
 
H

Helmut Weber

Hi Rob,

don't use a fix point like number of pages
and do something to a doc, which might
influence your fix point.

I wish, I could make this clearer :-(

Have a look at this one:

Sub TestXXX()
Dim lngPgs As Long ' number of pages
Dim lngPag As Long ' the page to go to
lngPgs = ActiveDocument.ComputeStatistics(wdStatisticPages)
If lngPgs Mod 2 <> 0 Then
lngPgs = lngPgs - 1 ' odd number of pages
End If
For lngPag = lngPgs To 2 Step -2
Selection.GoTo What:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=lngPag
' now for moving the selection
' and deleting the first 10 lines
Next
End Sub

Assuming, that you want to delete the first
ten lines form every even numbered page.

If you proceed from the first page,
then the number of pages may change,
and affect our fix point.

If you start from the last page,
your fixpoint is zero,
and that never changes.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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