Listing Bookmark By Location in Document

M

MT DOJ Help Desk

Word 2000

I have a simple macro that populates an array with bookmark names by reading
the contents of the Bookmarks collection. The only problem is that it fills
the array with the bookmark names in alphabetical order, and I need them
listed in the order in which they appear in the document from top to bottom.
Is there a way to sort the Bookmarks collection by location, and then use
that sorted list to populate an array?

-- Tom

MT DOJ Help Desk

Making the world a safer place.
 
J

Jonathan West

MT DOJ Help Desk said:
Word 2000

I have a simple macro that populates an array with bookmark names by reading
the contents of the Bookmarks collection. The only problem is that it fills
the array with the bookmark names in alphabetical order, and I need them
listed in the order in which they appear in the document from top to bottom.
Is there a way to sort the Bookmarks collection by location, and then use
that sorted list to populate an array?

Hi Tom

This goes through the bookmarks alphabetically

Dim oBookmark
For Each oBookmark in ActiveDocument.Bookmarks
'your code here
Next oBookmark

and this goes through the booknmarks in the order they appear in the
document

Dim oBookmark
For Each oBookmark in ActiveDocument.Range.Bookmarks
'your code here
Next oBookmark
 
J

Jezebel

You can determine the location by checking the Bookmark.Range.Start property
for each bookmark. You'll still have to sort the bookmarks yourself: either
sort them as you go by maintaining parallel arrays of start positions and
names, or read them all into a collection and then sort.
 
M

MT DOJ Help Desk

Jonathan,

Thanks for your help. I knew there had to be a way to do it, but I wasn't
having much luck finding it in the online Help.

-- Tom

MT DOJ Help Desk

Making the world a safer place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top