Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Loop through document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob - 19 Feb 2007 15:15 GMT
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
Helmut Weber - 19 Feb 2007 16:35 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

>I have a document that I would like to do the following until there are no
>more pages to perform this action:
[quoted text clipped - 8 lines]
>
>Rob
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.