Determine if a line contains a bookmark?

S

STeve

hi guys,

Is it possible to determine whether the current line contains a
bookmark? What I am trying to do is to hide information about the
section by storing it in a bookmark. So when I parse the document, I
know what to save the name of the section as by using that hidden
bookmark as the name of the file.

THanks in advance,
Steve
 
L

Larry

Application.ScreenUpdating = False
Selection.HomeKey wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
If Selection.Bookmarks.Count > 0 Then X = True
Selection.Collapse wdCollapseStart
If X = True Then
MsgBox "Bookmark in current line."
Else
MsgBox "No bookmark in current line."
End If


Larry
 
S

STeve

Thanks that worked great!

One more quick question. Is there a way to determine which bookmark
is currently selected depending on which line you are on. Like using
the bookmark.name function.

THanks in advance
Steve
 
L

Larry

This is crude and could be improved, but it gets you the information you
want.

Dim r As Range
Application.ScreenUpdating = False

Selection.HomeKey wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Set r = Selection.Range
X = r.Bookmarks.Count
Selection.Collapse wdCollapseStart

If X < 1 Then
MsgBox "No bookmark in current line."
Else
For i = 1 To X
MsgBox "Bookmark(s) in current line: " & r.Bookmarks(i).Name
Next i
End If
 

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