John Simpson MAI

Hello,

I'm using VSTO 2005 SE and I'm having lots of problems trying to retrieve the name of the active bookmark. I want to dynamically pass the name of the active Word 2003 bookmark to an Actions Pane to do something, but there appear to be no properties that could retrieve this from Word. Similar in concept to ActiveDocument, I'd love to see some functionality like ActiveBookmark, but alas there appears to be nothing this easy.

My collegues and I are stumped. I've come up with three possibilities that don't work:

  1. I can cycle thru the bookmark collection easily enough, but to pass a bookmark name via Me.Application.ActiveDocument.Bookmarks(index).Name, I have to know either the numerical index for the bookmark (which dynamically I don't) or the bookmark name (which defeats my purpose).
  2. I don't want to hard code text in each handler because I have hundreds of bookmarks; setting them to all to a single function and passing the name of the active bookmark is my goal.
  3. Casting the sender event to object, control, etc. and using Object.name, Object.Control, etc. returns null

So... is there a way to dynamically retrieve the index of the currently active Word bookmark and if not, is there a way to retreive the bookmark name

Thank you for your time. As always, it's appreciated.

John



Re: Visual Studio Tools for Office The active bookmark in VSTO 2005

Cindy Meister

First, test whether the selection is in a bookmark:

Me.Application.Selection.Bookmarks.Count

If this doesn't return zero, then get the name of the bookmark:

Me.Application.Selection.Range.Bookmarks(1).Name

Note that bookmarks can be nested, so the index (1) may not always be appropriate