Skip to main content

How to print list of bookmarks in Word document?

Have you ever tried to print a list of bookmarks in a Word document? Here we will show you methods to achieve it.

Extract all bookmarks and print with VBA

Directly print all bookmarks with VBA


Extract all bookmarks and print with VBA

The below VBA code will help to list all bookmarks from current document to a new one, and you can manually print the extracted bookmarks as you need. Please do as follows.

1. Open the document you will print the bookmarks, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below code into the Module window.

VBA code: Extract all bookmarks to a new document

Sub ExtractBookmarksInADoc()
'Updated by Extendoffice 20181123
    Dim xRow As Long
    Dim xTable As Table
    Dim xDoc As Document
    Dim xBookMark As Bookmark
    Dim xBookMarkDoc As Document
    Dim xParagraph As Paragraph
    Set xDoc = ActiveDocument
    If xDoc.Bookmarks.Count = 0 Then
        MsgBox "There is no bookmark in this document", vbInformation, "KuTools for Word"
        Exit Sub
    End If
    Set xBookMarkDoc = Documents.Add
    xRow = 1
    Selection.TypeText "BookMarks in " & "'" & xDoc.Name & "'"
    Set xTable = Selection.Tables.Add(Selection.Range, 1, 3)
    xTable.Borders.Enable = True
    With xTable
        .Cell(xRow, 1).Range.Text = "Name"
        .Cell(xRow, 2).Range.Text = "Texts"
        .Cell(xRow, 3).Range.Text = "Page Number"
        For Each xBookMark In xDoc.Bookmarks
            xTable.Rows.Add
            xRow = xRow + 1
            .Cell(xRow, 1).Range.Text = xBookMark.Name
            .Cell(xRow, 2).Range.Text = xBookMark.Range.Text
            .Cell(xRow, 3).Range.Text = xBookMark.Range.Information(wdActiveEndAdjustedPageNumber)
            xDoc.Hyperlinks.Add Anchor:=.Cell(xRow, 3).Range, Address:=xDoc.Name, _
              SubAddress:=xBookMark.Name, TextToDisplay:=.Cell(xRow, 3).Range.Text
        Next
    End With
    xBookMarkDoc.SaveAs xDoc.Path & "\" & "Bookmarks in " & xDoc.Name
End Sub

3. Press the F5 key to run the code.

Then a new document is created automatically with all bookmarks of specified document listing inside.

4. You can click File > Print to print the list of extracted bookmarks as you need.


Directly print all bookmarks with VBA

If you want to directly print all bookmarks in current document, please do as follows.

1. Open the document you will print the bookmarks, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below code into the Module window.

VBA code: Print all bookmarks in a document

Sub ExtractBookmarksInADoc()
'Updated by Extendoffice 20181123
    Dim xRow As Long
    Dim xTable As Table
    Dim xDoc As Document
    Dim xBookMark As Bookmark
    Dim xBookMarkDoc As Document
    Dim xParagraph As Paragraph
    On Error Resume Next
    Set xDoc = ActiveDocument
    If xDoc.Bookmarks.Count = 0 Then
        MsgBox "There is no bookmark in this document", vbInformation, "KuTools for Word"
        Exit Sub
    End If
    Set xBookMarkDoc = Documents.Add
    xRow = 1
    Selection.TypeText "BookMarks in " & "'" & xDoc.Name & "'"
    Set xTable = Selection.Tables.Add(Selection.Range, 1, 3)
    xTable.Borders.Enable = True
    With xTable
        .Cell(xRow, 1).Range.Text = "Name"
        .Cell(xRow, 2).Range.Text = "Texts"
        .Cell(xRow, 3).Range.Text = "Page Number"
        For Each xBookMark In xDoc.Bookmarks
            xTable.Rows.Add
            xRow = xRow + 1
            .Cell(xRow, 1).Range.Text = xBookMark.Name
            .Cell(xRow, 2).Range.Text = xBookMark.Range.Text
            .Cell(xRow, 3).Range.Text = xBookMark.Range.Information(wdActiveEndAdjustedPageNumber)
            xDoc.Hyperlinks.Add Anchor:=.Cell(xRow, 3).Range, Address:=xDoc.Name, _
              SubAddress:=xBookMark.Name, TextToDisplay:=.Cell(xRow, 3).Range.Text
        Next
    End With
    xBookMarkDoc.SaveAs xDoc.Path & "\" & "Bookmarks in " & xDoc.Name
    xBookMarkDoc.PrintOut
    xBookMarkDoc.Close
    Kill xBookMarkDoc.Path
End Sub

3. Press the F5 key to print the bookmarks directly.

Best Office Productivity Tools

Kutools for Word - Elevate Your Word Experience with Over 100 Remarkable Features!

🤖 Kutools AI Assistant: Transform your writing with AI - Generate Content  /  Rewrite Text  /  Summarize Documents  /  Inquire for Information based on Document, all within Word

📘 Document Mastery: Split Pages  /  Merge Documents  /  Export Selection in Various Formats (PDF/TXT/DOC/HTML...)  /  Batch Convert to PDF  /  Export Pages as Images  /  Print Multiple Files at once...

Contents Editing: Batch Find and Replace across Multiple Files  /  Resize All Pictures  /  Transpose Table Rows and Columns  /  Convert Table to Text...

🧹 Effortless Clean: Sweap away Extra Spaces  /  Section Breaks  /  All Headers  /  Text Boxes  /  Hyperlinks  /  For more removing tools, head to our Remove Group...

Creative Inserts: Insert Thousand Separators  /  Check Boxes  /  Radio Buttons  /  QR Code  /  Barcode  /  Diagonal Line Table  /  Equation Caption  /  Image Caption  /  Table Caption  /  Multiple Pictures  /  Discover more in the Insert Group...

🔍 Precision Selections: Pinpoint specific pages  /  tables  /  shapes  /  heading paragraphs  /  Enhance navigation with more Select features...

Star Enhancements: Navigate swiftly to any location  /  auto-insert repetitive text  /  seamlessly toggle between document windows  /  11 Conversion Tools...

👉 Want to try these features? Kutools for Word offers a 60-day free trial, with no limitations! 🚀
Free Download     Read More     Buy Now
 
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations