Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Bookmark name from PreviousBookmarkID

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jw - 13 Aug 2006 23:41 GMT
Word 2003 sp2

I want to return the name of the bookmark preceding the cursor.  By
analogy with the second example in the VBA Help file entitled
"PreviousBookmarkID property", I wrote the following preliminary
code:

   Dim xBookmarkNumber As Long
   xBookmarkNumber = Selection.PreviousBookmarkID
   MsgBox xBookmarkNumber
   MsgBox ActiveDocument.Bookmarks(xBookmarkNumber).Name

When I tested this code by placing the cursor after the first bookmark
in the document, xBookmarkNumber was identified correctly as 1.
However, the name returned by
ActiveDocument.Bookmarks(xBookmarkNumber).Name was that of a different
bookmark.  I finally figured out that the name being returned was the
name of the first bookmark IF THE BOOKMARKS ARE SORTED BY NAME!!!

Can anybody tell me how to retrieve the name of the previous bookmark?
Thanks.

PS: I realize that the following code will retrieve the name:

   MsgBox Selection.Bookmarks(1).Name

However, this requires that you select text either surrounding a
placeholder bookmark or within an enclosure bookmark, which I don't
want to have to take the trouble to do.  (And in any case, the code
provided in the Help file doesn't work properly!)
Jay Freedman - 14 Aug 2006 01:07 GMT
Odd as it may seem, the syntax

  ActiveDocument.Bookmarks(xBookmarkNumber)

returns the bookmarks in alphabetic order by name, while

  ActiveDocument.Range.Bookmarks(xBookmarkNumber)

returns them in location order.

In the Insert > Bookmark dialog, the option buttons for sorting the
list by name or by location work exactly the same way.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>Word 2003 sp2
>
[quoted text clipped - 26 lines]
>want to have to take the trouble to do.  (And in any case, the code
>provided in the Help file doesn't work properly!)
jw - 14 Aug 2006 01:43 GMT
Excellent.  Thanks very much.

> Odd as it may seem, the syntax
>
[quoted text clipped - 46 lines]
> >want to have to take the trouble to do.  (And in any case, the code
> >provided in the Help file doesn't work properly!)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.