View Single Post
  #4   Report Post  
SHNABY SHNABY is offline
Junior Member
 
Posts: 0
Default

Quote:
Originally Posted by WordQueen View Post
I need to print a list of bookmark names in a template. I can't figure out
how to do so. Any words of wisdom?
Hi WordQueen,
The quickest way to extract a list of bookmark is to run a macro.
The following macro will export all bookmarks within a document to a new document and arrange bookmark names, texts, and page numbers in a table.

Just press "Alt+ F11" to open VBA editor, create a new module and run the following codes:

Sub ExtractBookmarksInADoc()
Dim objBookmark As Bookmark
Dim objTable As Table
Dim nRow As Integer
Dim objDoc As Document, objNewDoc As Document
Dim objParagraph As Paragraph

Set objDoc = ActiveDocument

If objDoc.Bookmarks.Count = 0 Then
MsgBox ("There is no bookmark in this document.")
Else
Set objNewDoc = Documents.Add

Selection.TypeText Text:="Bookmarks in " & "'" & objDoc.Name & "'"

Set objTable = Selection.Tables.Add(Range:=Selection.Range, numrows:=1, numcolumns:=3)
objTable.Borders.Enable = True
nRow = 1

For Each objParagraph In objNewDoc.Paragraphs
If objParagraph.Range.Style = "Caption" Then
objParagraph.Range.Delete
End If
Next objParagraph

With objTable
.Cell(1, 1).Range.Text = "Name"
.Cell(1, 2).Range.Text = "Texts"
.Cell(1, 3).Range.Text = "Page Number"

For Each objBookmark In objDoc.Bookmarks
objTable.Rows.Add
nRow = nRow + 1
.Cell(nRow, 1).Range.Text = objBookmark.Name
.Cell(nRow, 2).Range.Text = objBookmark.Range.Text
.Cell(nRow, 3).Range.Text = objBookmark.Range.Information(wdActiveEndAdjustedP ageNumber)
objDoc.Hyperlinks.Add Anchor:=.Cell(nRow, 3).Range, Address:=objDoc.Name, _
SubAddress:=objBookmark.Name, TextToDisplay:=.Cell(nRow, 3).Range.Text
Next objBookmark
End With
End If
objNewDoc.SaveAs2 FileName:=objDoc.Path & "\" & "Bookmarks in " & objDoc.Name
End Sub


The page numbers are in link, so you can follow them and quickly jump to the bookmark location.

For more detailed information, you can refer to this article:

https://www.datanumen.com/blogs/batc...word-document/

Hope that helps!

SHNABY

Last edited by SHNABY : April 25th 17 at 08:20 AM