• Bookmarks in word (word 97)

    Author
    Topic
    #1771220

    Help! Is it possible to view the names of the bookmarks that have been created in a word document? I can get the locations to show but not the actual name of the bookmarks? Thanks!

    Viewing 2 reply threads
    Author
    Replies
    • #1793379

      If you go to Insert, Bookmark, you should see a list of exixting bookmarks. Also if you use Edit, Go To and select bookmark, you get a list of names that you can select from.

      Andrew C

    • #1793381

      If you’re not averse to using macros, here are a couple that are useful when building templates:

      This one will insert the name of each bookmark in the document, immediately after the location of the bookmark – never run this in your template! – always run it in a copy or in a document based on the template:

      Public Sub TypeEachBmkName()
      Dim aBmk As Bookmark
      Dim strBmkName As String
      
      If Documents.Count > 0 Then
          For Each aBmk In ActiveDocument.Bookmarks
              strBmkName = aBmk.Name
              aBmk.Range.InsertAfter strBmkName
          Next aBmk
      End If
      End Sub
      

      This one produces a list of all the bookmarks in a given document, in a new document:

      Public Sub ListBookmarksByName()
      Dim myBook As Bookmark
      Dim strBooklist As String
      strBooklist = "Alphabetical list of bookmarks in " _
          & ActiveDocument.FullName & ":" & vbCr
      
      For Each myBook In ActiveDocument.Bookmarks
          strBooklist = strBooklist & myBook.Name & vbCr
      Next
      Documents.Add
      Selection.TypeText strBooklist
      End Sub
      

      Gary

    • #1793403

      Prime Consulting makes an add-on that includes a toolbar that, when you click it, lists all your bookmarks. If you click one, you’re sent there. It’s a goodie. Check their site at http://www.primeconsulting.com/software/index.html

      Fred

      • #1793404

        I’ll check it out, but I’m curious. How is this different from clicking on the browse object and selecting GoTo bookmark or pressing F5 and picking bookmark?

        I guess I’ll find out.

        • #1793412

          Charles,

          not much difference. The bookmark also has a toggle to view the bookmark delimiters [ ].

          fred

        • #1793431

          Hi Charles:

          The Prime Consulting gives you a drop down menu on a toolbar. It’s much faster to scroll the toolbar listings than click a drop down arrow in a dialog box. You can name the toolbar button with a “&” so that you can open it with an “Alt+hotkey” & then arrow up or down through your bookmarks.

          • #1793455

            What this discussion hasn’t directly answered so far is whether there is a way to identify a bookmark’s name when you see the marker in your document. I assume that’s what the original question was asking. Ideallly I would like to be able to point at a bookmark symbol and have a little pop-up tell me its name. I often work with documents (training manuals) that have been through several versions over the years. They are often littered with bookmarks and it would be great to be able to find out what they are, so as to be able to delete those that are no longer needed..

            Any way of doing that? I too would love to know.

            (You can do it the long way round, by trial and error using the go to function until you strike lucky, but it’s not very satisfactory.)

            Ian

            • #1793456

              Hi Ian,

              You could use the following code:

              Public Sub GetSelectedBookmarkName()
              MsgBox Selection.Bookmarks(1).Name
              End Sub

              Just click an insertion point anywhere inside the bookmark, then run the macro.

              Gary

            • #1793457

              Gary:

              This is great! I just put it on my Text Shortcut Menu. Now I can right click any bookmark (I keep View/Bookmarks on) & get its name. bravo

            • #1793461

              That’s just what I wanted. Nice one, Gary.

              Phil – forgive my ignorance, but how do I add this to the shortcut menu so I can just right-click them too.

              Ian

            • #1793462

              Don’t worry Phil – I’ve worked it out.

              Ian

            • #1793475

              Like Phil, I think this is great! Sometimes, though, my bookmarks get a bit tangled, especially if they are put in by macros. I came up with the following modification:

              Sub GetSelectedBookmarkName()
              ' from Gary Frieder on Woody's Lounge
              ' modified with error handler & multiple bookmark handler by Charles Kenyon
              '
              ' Add to context menus
              Dim iBookCount As Integer   'number of bookmarks
              Dim iCount As Integer       'counter for loop
              Dim sName As String         'holds bookmark name in loop
              '
              On Error GoTo NoBookMark
                  iBookCount = Selection.Bookmarks.Count
                  If iBookCount > 1 Then
                      For iCount = 1 To iBookCount
                          sName = Selection.Bookmarks(iCount).Name
                          MsgBox Prompt:="The selection is in " & iBookCount & " bookmarks!" _
                              & vbCrLf & "The name of bookmark No." & iCount & " is " _
                              & sName & ".", _
                              Buttons:=vbInformation, Title:="Multiple Bookmarks Names"
                      Next iCount
                      Exit Sub
                  End If
                  MsgBox Prompt:="The bookmark's name is " _
                      & Selection.Bookmarks(1).Name & ".", _
                      Buttons:=vbInformation, Title:="Bookmark Name"
                  Exit Sub
              NoBookMark:
                  MsgBox Prompt:="There is no bookmark here.", _
                      Title:="Sorry!", Buttons:=vbExclamation
              End Sub
              

              So far it works well. Thought I would share.

            • #1793478

              Hi Charles,

              A question and a suggested tweak:

              A question about the error handler and message – it looks like you want this message to display if the selection contains 0 bookmarks, but it’s unclear what condition is expected to cause the error – if there are no bookmarks in the selection, you’d get a count of 0, but that won’t cause an error to occur.

              Also, it looks like if there is more than one bookmark in the selection, then both message boxes are going to show(?) (since you have the second one outside the If structure.)

              One way to handle all the different Count eventualities would be to use a Select Case structure – this would be along the lines of:

              Select Case iBookCount
              Case 0
              MsgBox saying there’s no bookmarks
              Case 1
              MsgBox saying there’s one bookmark
              Case Else
              Loop and msgbox saying there’s multiple bookmarks
              End Select

              – a side benefit being that you don’t need to use an Error event to prompt the display of the 0 bookmarks MsgBox.

              Regards,
              Gary

            • #1793487

              Hi Gary,

              Thanks for the feedback.

              I wrote this for use in a context menu, assuming that the person using it might not have bookmark delimiters displayed. If the selection point is not in (or does not contain) any bookmarks, the error handler picks up on trying to get the name of a non-existing bookmark. (Member of collection does not exist.)

              MsgBox Selection.Bookmarks.Name will generate such an error. You are right that I could test for Count = 0 instead. I’m not aware of any reason for preferring one method over the other (except that the error handler would also be triggered by an unforseen error).

              If there is more than one bookmark, the code produces one message box for each bookmark, giving the total number of bookmarks, the number of this bookmark, and the name of this bookmark. Then it executes the Exit Sub statement before reaching the end of the If structure. I could have put in an Else structure instead but was just typing code and already had the message box for one bookmark done.

            • #1793473

              You could also click near a bookmark (anywhere within its range) and press ctrl+shift+F5. This combination could be assigned to an “F” key if you prefer.

    Viewing 2 reply threads
    Reply To: Bookmarks in word (word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: