PDA

View Full Version : Solved: Search bookmarks by location



murphy84
10-05-2007, 03:11 AM
Hi,

Just a quick question. I need to search bookmarks by location in the document. Does anyone know how I would go about doing that?

The normal:-


For each bMark in ActiveDocument.Bookmarks
..
..
Next


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.

murphy84
10-05-2007, 03:42 AM
Think the following works...

ActiveDocument.Range.Bookmarks.DefaultSorting =wdSortByLocation

Perhaps I should have looked before posting!

fumei
10-05-2007, 03:47 AM
Thanks for posting a followup.

murphy84
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)
..
..
..
Next i


Any help would be much appreciated!

fumei
10-05-2007, 04:48 AM
If you read help:

Remarks
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?

murphy84
10-05-2007, 04:52 AM
It's okay, I've sorted it now.

It appears that :-

For Each bMark In ActiveDocument.Bookmarks
Next

Searches the bookmarks in name order but...

For Each bMark In ActiveDocument.Range.Bookmarks
Next

Searches the bookmarks in location order. Seems to make sense!

Definately solved now :yes

fumei
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.