|
-
May 2nd, 2006, 02:54 PM
#1
Thread Starter
Member
[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?
Last edited by Hack; May 4th, 2006 at 06:58 AM.
Reason: Added [RESOLVED] to thread title
-
May 2nd, 2006, 05:15 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 3rd, 2006, 05:52 AM
#3
Thread Starter
Member
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???
-
May 4th, 2006, 06:43 AM
#4
Thread Starter
Member
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
-
Jul 2nd, 2009, 04:38 PM
#5
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|