Ian
Sat Oct 13 16:33:42 PDT 2007
Thanks Shauna
You're a "Champ".
Does the job very simply.
Also works with Comments collection.
Tks again
Ian B
"Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in message
news:%23ErCT0eDIHA.3712@TK2MSFTNGP02.phx.gbl...
> Hi Ian
>
> ActiveDocument.bookmarks(1) refers to the first bookmark in the document.
If
> there are no bookmarks in the document it will return Nothing.
>
> Selection.Bookmarks(1) refers to the first bookmark within the selection.
If
> there are no bookmarks in the Selection it will return Nothing.
>
> So something like this will work:
>
> Sub PlayWithBookmarks()
>
> Dim BM As Word.Bookmark
>
> 'If there are any bookmarks at the selection, then ...
> If Selection.Bookmarks.Count > 0 Then
>
> '... get the first bookmark within the selection
> Set BM = Selection.Bookmarks(1)
>
> 'Tell the user the name of the bookmark
> MsgBox BM.Name
>
> End If
>
> 'You can test to see if BM is a bookmark
> If BM Is Nothing Then
> 'there was no bookmark at the selection
> Else
> 'Do something with the bookmark,
> 'eg, make the range of the bookmark pink
> BM.Range.Font.Color = wdColorRose
> End If
>
> End Sub
>
>
> Have a look at Word's VBA help at the Bookmarks property for more examples
> and explanation.
>
> Hope this helps.
>
> Shauna Kelly. Microsoft MVP.
>
http://www.shaunakelly.com/word
>
>
> "Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message
> news:%23hYwQjeDIHA.5024@TK2MSFTNGP06.phx.gbl...
> >I have a bookmark spanning a selection.
> > I place the insertion point within the bookmark.
> > I need to use VBA to determine the name of the bookmark containing the
> > insertion point.
> > Sounds simple, but I can't get the index, which I need to get the name.
> > As a last resort I could note the range of insertion point, and search
all
> > bookmarks for one spanning that range, but that's a bit "heavy".
> > Any help much appreciated
> >
> > TIA
> >
> > Ian B
> >
> >
>
>