Any ideas of how in Word 2000 VBA to sort bookmarks

N

Nic Rye

Hi

OK what I'm after doing is in Word 2000 VBA a method of
sorting a bookmarks collection without doing the long-
handed way if at all possible.

Cheers
Nic
 
J

JGM

Note: Second try at replying, there is something wrong either with the
Microsoft News Server or my computer...

Hi Nic,

Maybe you should have posted this in the Word.VBA.General group...
In any case...

Have you looked at the VBA help available with Word? Do ALT-F11 to access
the VBE window, then F2 to get to the Object browser, then type "Bookmark"
in the search field... and here is an example straight from the help topic
"Bookmark, Property":

If ActiveDocument.Bookmarks.Count >= 1 Then
ReDim aMarks(ActiveDocument.Bookmarks.Count - 1)
i = 0
For Each aBookmark In ActiveDocument.Bookmarks
aMarks(i) = aBookmark.Name
i = i + 1
Next aBookmark
End If

This will generate a variable that stores all the bookmark names. If you
sort the bookmarks first (see below) you can output a list that is either
alphabetical or by location in the document.

Altenatively, if you had typed "Sort" in the search field, you would have
eventually found a property called "DefaultSort" that has to do with
bookmarks, as in the following example:

ActiveDocument.Bookmarks.DefaultSorting = wdSortByLocation
'or wdSortByName
Dialogs(wdDialogInsertBookmark).Show

Finally, if you you want a full list, inlcuding a list of the hidden
bookmarks Word automatically genrates (when you create a Table of Contents
for example), use the "ShowHidden" property as in:

ActiveDocument.Bookmarks.ShowHidden = True
For Each aBookmark In ActiveDocument.Bookmarks
If Left(aBookmark.Name, 1) = "_" Then MsgBox aBookmark.Name
Next aBookmark

This works because all hidden bookmarks generated by Word on the fly start
with an underscore character.

HTH
Cheers!
 
N

Nic Rye

JGM

Sorry about the misplaced posting but wasn't aware there
was a Word.VBA.General and still can't find it.

Had already tried what you suggested and it does effect
the collection, which remains in the order of first
bookmark created to tyhe last.

Nevermind have created a long-hand alphabetical version
now to try sorting for location.

Cheers
Nic
 
C

Cindy Meister -WordMVP-

Hi Nic,
Sorry about the misplaced posting but wasn't aware there
was a Word.VBA.General and still can't find it.
I see you're using the CDO interface; not all newsgroups
are listed there. Have you ever tried using a newsreader?
Or using Outlook Express to access the newsgroups? That
would give you access to ALL the groups, including the
word.vba ones.
Had already tried what you suggested and it does effect
the collection, which remains in the order of first
bookmark created to tyhe last.
Read the Help on the bookmarks stuff really carefully.
There are two ways to "ask" for the boookmarks collection:
- ActiveDocument.Bookmarks
- ActiveDocument.Range.Bookmarks

One brings the order in which they were inserted; the other
the alphabetical order.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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