In this article, we want to provide you with two quick ways to batch delete multiple bookmarks in your Word document.
Normally you can add or delete a single bookmark in Word document without any obstacle. However, when it comes to multiple bookmarks, you may feel your hands are tied.
Fortunately, there is a powerful tool in Word that is the VBA editor. Therefore, we will use macros to help you batch remove multiple bookmarks in a document.
Method 1: Batch Delete All Bookmarks in a Document
- First and foremost, invoke the VBA editor in Word by pressing “Alt+ F11”.
- Next on the left “Project” panel, click on “Normal”.
- Then click “Insert” tab and choose “Module” on its menu.
- Double click to open module.
- Now paste following codes there:
Sub DeleteAllBookmarksInDoc() Dim objBookmark As Bookmark Dim nBookmark As Integer Dim strButtonValue As String Dim objDoc As Document Application.ScreenUpdating = False Set objDoc = ActiveDocument nBookmark = objDoc.Bookmarks.Count If nBookmark > 0 Then strButtonValue = MsgBox("Do you want to remove all " & nBookmark & " bookmark(s) in this document?", vbYesNo) If strButtonValue = vbYes Then For Each objBookmark In objDoc.Bookmarks objBookmark.Delete Next objBookmark MsgBox ("All bookmarks in this document have been deleted.") Else Exit Sub End If End If Application.ScreenUpdating = True End Sub
- Then click “Run” button.
- Next you will get an asking box. And you can see the total number of bookmarks in current document. Click “Yes” to delete them all, or “No” to exit macro.
- If you choose “Yes”, you shall receive a message such as below:
Method 2: Batch Delete All Bookmarks in a Selection
Admittedly, there are also times when you have to remove several bookmarks but keep some intact. Similarly, we will run a macro on a selection to get the job done.
- To start off, repeat above steps to install and run a macro.
- Remember to replace macro with this one:
Sub DeleteAllBookmarksInSelection() Dim objBookmark As Bookmark Dim nBookmark As Integer Dim strButtonValue As String Application.ScreenUpdating = False nBookmark = Selection.Bookmarks.Count If nBookmark > 0 Then strButtonValue = MsgBox("Do you want to remove all " & nBookmark & " bookmark(s) in this selection?", vbYesNo) If strButtonValue = vbYes Then For Each objBookmark In Selection.Bookmarks objBookmark.Delete Next objBookmark MsgBox ("All " & nBookmark & " bookmark(s) in this selection have been deleted.") Else Exit Sub End If End If Application.ScreenUpdating = True End Sub
- Before running the macro, you shall make a selection over a range of contents.
- And in the process of executing codes, you shall receive the same 2 message boxes shown in method 1.
The result is you will only have bookmarks in the selection removed.
Get Ready for Document Corruption
Data loss can happen to anyone anytime. And its unpredictability makes us take a chance on not running into the bad luck. Speaking of the topic to repair docx, you can never miss picking an efficient repairing tool in advance.
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including xls repair and pdf repair software products. For more information visit www.datanumen.com