Word VBA

Murray Brown
Murray Brown used Ask the Experts™
on
Is it possible to get the name of a single bookmark that I have
selected in Word using VBA?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead
Commented:
try:
Dim bk As Bookmark
    For Each bk In Application.Selection.Bookmarks
        Debug.Print bk.Name
    Next

Open in new window

Retired
Top Expert 2012
Commented:
Try this:
Sub WhichBM()
    Dim bmk As Bookmark
    If Selection.Range.Bookmarks.Count > 0 Then
        MsgBox "Bookmark '" & Selection.Range.Bookmarks(1).Name & "' is the first one in the Selection"
    Else
        MsgBox "No bookmarks in Selection"
    End If
End Sub

Open in new window

Murray BrownASP.net/VSTO Developer

Author

Commented:
Thank you both

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial