How to Batch Change Multiple Bookmark Names in Your Word Document

In today’s article, we are going to provide you with the way to batch change multiple bookmark names in your Word document.

There is a little tricky to change a bookmark name in Word document. And in one of our previous article, we have explained ways to you. For detailed information, you can refer to this link:2正确方法to Change a Bookmark Name in Your Word Document

This time, we want to offer you the way to batch change multiple bookmark names in your document.Batch Change Multiple Bookmark Names in Your Word Document

Batch Change Multiple Bookmark Names via VBA

  1. First and foremost, insert a 2-column table of multiple rows at the end of your target document. In the table, enter the original bookmark names in the first column. And enter new names in the second. Also make sure you put cursor inside the table. Here is the example:Insert a Table
  2. Then invoke the VBA editor in Word by pressing “Alt+ F11”.
  3. Next in the editor, click “Normal” on the left column.
  4. And on the menu bar above, click “Insert” tab.
  5. On the drop-down menu of “Insert”, choose “Module”.Click "Insert"->Click "Module"" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20266%20185'%3E%3C/svg%3E" alt="Click "Normal"->Click "Insert"->Click "Module"" width="266" height="185" data-lazy-src="//www.circareview.com/download/blogs/wp-content/uploads/2017/07/Click-Normal-then-Click-Insert-then-Click-Module-25.jpg">
  6. Double click on new module to open it and then paste following codes in the coding area:
Sub BatchChangeTheBookMarkNameAndUpdateCrossReference() Dim nCurrentTableIndex As Integer Dim objTable As Table Dim nRowNumber As Integer Dim objOriBookMarkList As Cell Dim objOriBookMarkListR As Range Dim objNewBookMarkListR As Range Dim strBookMarkName As String Dim strNewName As String Dim objBookMarkRange As Range Dim objField As Field Dim strFieldCode As String nCurrentTableIndex = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count Set objTable = ActiveDocument.Tables(nCurrentTableIndex) nRowNumber = 1 For Each objOriBookMarkList In objTable.Columns(1).Cells Set objOriBookMarkListR = objOriBookMarkList.Range objOriBookMarkListR.MoveEnd Unit:=wdCharacter, Count:=-1 Set objNewBookMarkListR = objTable.Cell(nRowNumber, 2).Range objNewBookMarkListR.MoveEnd Unit:=wdCharacter, Count:=-1 If objOriBookMarkListR.Text <> "" Then strBookMarkName = objOriBookMarkListR.Text strNewName = objNewBookMarkListR.Text End If With ActiveDocument If .Bookmarks.Exists(strBookMarkName) Then Set objBookMarkRange = .Bookmarks(strBookMarkName).Range .Bookmarks(strBookMarkName).Delete .Bookmarks.Add Name:=strNewName, Range:=objBookMarkRange ' Update the cross-reference If .Fields.Count >= 1 Then For Each objField In .Fields strFieldCode = objField.Code.Text If strFieldCode = " REF " & strBookMarkName & " \h " Then objField.Code.Text = Replace(strFieldCode, strBookMarkName, strNewName, , 1, vbTextCompare) objField.Update End If Next objField End If Else MsgBox ("The bookmark: " & strBookMarkName & " is not founded.") End If End With Set objBookMarkRange = Nothing nRowNumber = nRowNumber + 1 Next MsgBox ("All bookmarks in the table list have been renamed.") End Sub
  1. Last but not the least, click “Run” or hit “F5” to execute codes.Paste Macro->Click

When the process is done, there will be a message box, such as below:Result Box

You can also click “Insert” tab and then the “Bookmark” to trigger the “Bookmark” dialog box. Now you can see the bookmark names have been changed.Click "Bookmark"" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20766%20583'%3E%3C/svg%3E" alt="Click "Insert"->Click "Bookmark"" width="766" height="583" data-lazy-srcset="//www.circareview.com/blogs/wp-content/uploads/2017/07/Click-Insert-then-Click-Bookmark.jpg 766w, //www.circareview.com/blogs/wp-content/uploads/2017/07/Click-Insert-then-Click-Bookmark-300x228.jpg 300w, //www.circareview.com/blogs/wp-content/uploads/2017/07/Click-Insert-then-Click-Bookmark-500x381.jpg 500w" data-lazy-sizes="(max-width: 766px) 100vw, 766px" data-lazy-src="//www.circareview.com/download/blogs/wp-content/uploads/2017/07/Click-Insert-then-Click-Bookmark.jpg">

Deal with Word Errors

Since Word is not immune to mistakes, it’s necessary to take the right action whenWord corruptionhappens. Most of the time, you can retrieve data back by picking a proficient repairing tool.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, includingfix Exceland pdf repair software products. For more information visitwww.circareview.com

Leave a Reply

Your email address will not be published.Required fields are marked*