954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

bookmark name in word

i want to write a vba macro that read the bookmark name on a selected place in word document.

halsoft
Newbie Poster
2 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

Hi Halsoft,

I am not sure what you want to do but here goes.

If what you want to do is look through your current selection to see if it contains a bookmark you could try something like this:

Public Sub test()
   Dim i As Integer
   
   For i = 1 To ActiveDocument.Bookmarks.Count
      If ActiveDocument.Bookmarks(i).Start >= Selection.Start And ActiveDocument.Bookmarks(i).End <= Selection.End Then
         'this bookmark is FULLY contained in the selection
         Debug.Print ActiveDocument.Bookmarks(i).Name
      ElseIf ActiveDocument.Bookmarks(i).Start >= Selection.Start And ActiveDocument.Bookmarks(i).End > Selection.End Then
         'this bookmark starts in the selection but finishes after the selection
         Debug.Print ActiveDocument.Bookmarks(i).Name
      ElseIf ActiveDocument.Bookmarks(i).Start < Selection.Start And ActiveDocument.Bookmarks(i).End <= Selection.End Then
         'this bookmark starts before the selection but finishes in the selection
         Debug.Print ActiveDocument.Bookmarks(i).Name
      Else
         'this bookmark is totally OUTSIDE the selection
      End If
   Next
End Sub


Now that you, and I 'cause I just found this, know how to use the .Start and .End you can also use this for any number of things.

However, if you want to do something else then please correct my understanding.

Happy coding

Yomet

Yomet
Junior Poster
134 posts since Nov 2005
Reputation Points: 16
Solved Threads: 10
 

hi yomet

its working very good

it save me a time for this weekend

mike bitter
halsoft

halsoft
Newbie Poster
2 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You