Bookmark: how to tell if cursor is in one? And which one?

T

Tsu Dho Nimh

Assuming there are bookmarked chunks of text in a document,

How can I tell if the cursor is in a bookmarked chunk of text or not?

How can I tell which bookmarked chunk of text the cursor is in an
highlight that bookmark's text
 
J

Jean-Guy Marcil

Hi Tsu Dho,

Try this:

'_______________________________________
Sub In_Bookmark_or_Not()

Dim BookName As String

If Selection.BookmarkID <> 0 Then

BookName = Selection.Bookmarks.Item(1).Name
MsgBox "The cursor is in the bookmark named: " & BookName & "."
ActiveDocument.Bookmarks(BookName).Select

Else

MsgBox "The cursor is not in a bookmark."

End If

End Sub
'_______________________________________


--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

Tsu Dho Nimh

Jean-Guy Marcil said:
Hi Tsu Dho,

Thanks. I actually figured it out myself. I always have
problems remembering which side of the = my variables need ot
be.

When I get back to work I'll post my own code.

'_______________________________________
Sub In_Bookmark_or_Not()

Dim BookName As String

If Selection.BookmarkID <> 0 Then

BookName = Selection.Bookmarks.Item(1).Name
MsgBox "The cursor is in the bookmark named: " & BookName & "."
ActiveDocument.Bookmarks(BookName).Select

Else

MsgBox "The cursor is not in a bookmark."

End If

End Sub
'_______________________________________


Tsu Dho Nimh
 
T

Tsu Dho Nimh

This was my version ... it works unless there are overlappin
bookmarks.

Sub WhatBookmarkIsThis()
' WhatBookmarkIsThis Macro
' Macro created 2/13/04 by


' declare a variable to hold the index position

Dim ID As Integer

'check for bookmark
If Selection.BookmarkID < 1 Then
MsgBox "The selection is not in a bookmark."

Else
'tell me what bookmark the cursor is in
'not reliable if bookmarks overlap where cursor is
'because it picks the outermost one

ID = Selection.BookmarkID
MsgBox "Bookmark Name is: "
ActiveDocument.Bookmarks(ID).Name

End If

End Su
 

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