[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:
Sub test()
counter = 0
Do Until (ActiveDocument.Bookmarks("\Sel") = ActiveDocument.Bookmarks("\EndOfDoc"))
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Selection.MoveDown unit:=wdLine, Count:=2
counter = counter + 1
MsgBox counter
Loop
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?
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.
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???
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:
Do Until (ActiveDocument.Bookmarks("\Sel").End = ActiveDocument.Bookmarks("\endofdoc").End
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Selection.MoveDown unit:=wdLine, Count:=1
'do something
Loop
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