View Full Version : Solved: Search bookmarks by location
10-05-2007, 03:11 AM
Just a quick question. I need to search bookmarks by location in the document. Does anyone know how I would go about doing that?
For each bMark in ActiveDocument.Bookmarks
Doesn't appear to work as it searches by name rather than location - and searching top/down is essential in what i need to do.
Thanks in advance.
10-05-2007, 03:42 AM
Think the following works...
Perhaps I should have looked before posting!
10-05-2007, 03:47 AM
Thanks for posting a followup.
10-05-2007, 04:32 AM
It looks like my solution doesn't work after all. It's still searching by name.
Anyone have any ideas what's up? The code i'm using is roughly as follows:-
ActiveDocument.Bookmarks.DefaultSorting = wdSortByLocation
For i = 1 To ActiveDocument.Bookmarks.Count
Set bMark = ActiveDocument.Bookmarks(i)
Any help would be much appreciated!
10-05-2007, 04:48 AM
If you read help:
This property doesn't affect the order of Bookmark objects in the Bookmarks collection.
SortByLocation only sorts the order shown in the dialog.
Perhaps if you tell us exactly what you are trying to do. What exactly do you mean by search by location?
10-05-2007, 04:52 AM
It's okay, I've sorted it now.
It appears that :-
For Each bMark In ActiveDocument.Bookmarks
Searches the bookmarks in name order but...
For Each bMark In ActiveDocument.Range.Bookmarks
Searches the bookmarks in location order. Seems to make sense!
Definately solved now :yes
10-05-2007, 05:03 AM
Very good. That is an excellent example/demonstration of Range!
The first refers to the ActiveDocument Bookmark collection, so will be in the order of the document.
The second refers to the Range Bookmark collection, and therefore will be in the order of the Range, which are numbers (ie. locations).
It does indeed make sense, and again, is a excellent example of understanding the object model.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.