Thread: [Solved] Macro to list all bookmarks
View Single Post
 
Old 02-09-2012, 03:49 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,359
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Marrick,

Try something based on the following. As coded, it adds the list to then end of the current document, but you could change that:
Code:
Sub ListBkMrks()
Application.ScreenUpdating = False
Dim oBkMrk As Bookmark, Rng As Range, StrTxt As String, StrStory As String
With ActiveDocument
  Set Rng = .Range.Characters.Last
  If .Bookmarks.count > 0 Then
    With Rng
    .Text = vbCrLf & "Bookmark" & vbTab & "Page" & vbTab & "Line" & vbTab & "Story Range" & vbTab & "Contents"
    For Each oBkMrk In ActiveDocument.Bookmarks
      .InsertAfter vbCrLf & oBkMrk.Name & vbTab
      .InsertAfter oBkMrk.Range.Characters.First.Information(wdActiveEndAdjustedPageNumber)
      .InsertAfter vbTab & oBkMrk.Range.Information(wdFirstCharacterLineNumber)
      Select Case oBkMrk.StoryType
        Case 1: StrStory = "Main text"
        Case 2: StrStory = "Footnotes"
        Case 3: StrStory = "Endnotes"
        Case 4: StrStory = "Comments"
        Case 5: StrStory = "Text frame"
        Case 6: StrStory = "Even pages header"
        Case 7: StrStory = "Primary header"
        Case 8: StrStory = "Even pages footer"
        Case 9: StrStory = "Primary footer"
        Case 10: StrStory = "First page header"
        Case 11: StrStory = "First page footer"
        Case 12: StrStory = "Footnote separator"
        Case 13: StrStory = "Footnote continuation separator"
        Case 14: StrStory = "Footnote continuation notice"
        Case 15: StrStory = "Endnote separator"
        Case 16: StrStory = "Endnote continuation separator"
        Case 17: StrStory = "Endnote continuation notice"
        Case Else: StrStory = "Unknown"
      End Select
      .InsertAfter vbTab & StrStory & vbTab & oBkMrk.Range.Text
    Next oBkMrk
    .Start = .Start + 1
    .ConvertToTable Separator:=vbTab
    .Tables(1).Rows.First.Range.Font.Bold = True
  End With
End If
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Bookmarks are listed alphabetically, whereas to were apparently trying to sort them by story range. You could sort the table on that column, if you wish.

Note too that the line numbers for some bookmarks will come out as -1. That's because line numbers only apply to the main story.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote