Results 1 to 5 of 5

Thread: [RESOLVED] loop between two bookmarks, or test EOF???

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    34

    Resolved [RESOLVED] loop between two bookmarks, or test EOF???

    Hi
    I needed to test for end of document equivalently to loop a section, better said between two bookmarks. Let's say from bookmark A to bookmark B, I want to iterate something, so I tried the following, on a document with a few lines:
    VB Code:
    1. Sub test()
    2. counter = 0              
    3. Do Until (ActiveDocument.Bookmarks("\Sel") = ActiveDocument.Bookmarks("\EndOfDoc"))
    4.     Selection.EndKey unit:=wdLine, Extend:=wdExtend
    5.     Selection.MoveDown unit:=wdLine, Count:=2
    6.     counter = counter + 1
    7.     MsgBox counter
    8. Loop  
    9. End Sub

    The problem with it is that it is an infinit loop, but I don't see why it isn't working as desired!!?? has someone an idea, please?
    Last edited by Hack; May 4th, 2006 at 06:58 AM. Reason: Added [RESOLVED] to thread title

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713

    Re: loop through bookmarks, or test EOF???

    Why not just iterate through the bookmarks collection? Are you just trying to count the number of bookmarks or ? There is a .Count property of the bookmarks collection.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    34

    Re: loop through bookmarks, or test EOF???

    no it's not what i want to do, I think I didn't express myself correctly.
    The problem:
    I want to do something just in a part of word document, let's say from a position A to the end of document, so naturally you think of a do..while/do..until loop, but then I didn't know how to test end of document in Word. So I thought maybe I could do it to test on the bookmarks, i.e., I will exit from the loop whenerver the predefined bookmark \Sel is equal to \endofDoc.
    DO you think it isnt maybe the best way to do it???or where can be the problem in the above vbcode which enters an infinit loop???

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    34

    Re:[RESOLVED] loop between two bookmarks, or test EOF???

    meanwhile I found a solution for my problem using .end property of bookmark. if you are interested here is the code:

    VB Code:
    1. Do Until (ActiveDocument.Bookmarks("\Sel").End = ActiveDocument.Bookmarks("\endofdoc").End  
    2.     Selection.EndKey unit:=wdLine, Extend:=wdExtend
    3.     Selection.MoveDown unit:=wdLine, Count:=1
    4.   'do something
    5. Loop

  5. #5
    New Member
    Join Date
    Jul 2009
    Posts
    1

    Re: [RESOLVED] loop between two bookmarks, or test EOF???

    Waiso,

    Thanks a million! I've been trying to accomplish this (simple??) procedure for weeks and ended up in that endless loop. I can finally move on, thanks to .end.

    Very grateful,

    Peg

Posting Permissions

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



Click Here to Expand Forum to Full Width