Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    May 2001
    Location
    MIA (takittodahous), Florida, USA
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Looping (word 2002 (xp?))

    Hi,

    I'm creating a loop that places a bookmark at the beginning of each page that starts with a certain string. I will then select and cut the text between the bookmarks to place into a new document (each) and save them out to text files. I was going to use an IF...THEN to keep my loop from being infinate. And i was going to ask if the current page is the last page then stop, already!

    Here's my problem - What member defines or contains the total pages and the current page... I've searched through help & the object browser but all I get is items for page numberING... which is not what I'm doing here...

    Maybe there's a better way to do this & I'm sure there is - either way.... HELP... hehe.

    Thanks as always for your generous assistance...

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Looping (word 2002 (xp?))

    Hello,

    There is no Page object in Word, as pagination is constantly changing. I strongly suggest re-thinking your problem, as trying to work with pages usually ends up in chasing your own tail.

    But you asked, so here goes:

    <pre>Sub LoopPages()
    Dim doc As Document
    Set doc = Selection.Document
    doc.Range(1, 1).Select
    Do
    doc.Bookmarks("page").Select
    If Selection.End = (doc.Range.End - 1) Then Exit Do
    Selection.GoToNext (wdGoToPage)
    Loop

    End Sub
    </pre>


  3. #3
    Star Lounger
    Join Date
    May 2001
    Location
    MIA (takittodahous), Florida, USA
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Looping (word 2002 (xp?))

    Cool - & thanks for the code. I used to do this a few years back, though - - I just can't find my old coding... typical stoner crap. hehe.

    I'll figure something out. Thanks again for all your help.

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Looping (word 2002 (xp?))

    You may want to take a look at the Selection.Information property in the online Help. It gives you access to various pieces of information, including Selection.Information(wdActiveEndPageNumber) and Selection.Information(wdNumberOfPagesInDocument).

  5. #5
    Star Lounger
    Join Date
    May 2001
    Location
    MIA (takittodahous), Florida, USA
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Looping (word 2002 (xp?))

    Thanks! I'll check it out. I ended up having the user run a bogus replace to count the number of times a particular string (a title) appears in the document. Then the user will enter that count into a variable which counts down on the loop. So that obviates the need to track an ever changing page count, as you said.

    Thanks for the push!

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Looping (word 2002 (xp?))

    VBScript's regular expressions (RegExp) object can count pattern matches in a long text string (e.g., the document body), but that may be more trouble than it's worth...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •