Renaming a bookmark in Word 2010
Is there a simpler or more effective way to rename bookmarks in Word documents?
There is no rename function built-in to Word. There are a couple of options to work around this lack:
Use an Add-in.
Use VBA.
Add-in Solution
Use the Bookmark Tool Add-In
It offers a friendly user interface for doing everything the standard Bookmark Dialog box will do plus much more.
Bookmark Tool was developed for Word 2003. It is wholly functional with Word 2007/2010.
...
With the "Add/Rename Bookmark" section, adding bookmarks is a breeze.
- As in the standard dialog, you simply select text, type a name in the field, and click "Add."
- Unlike the standard dialog, Bookmark Tool restricts key entry to valid bookmark name characters and alerts you if you attempt to create a duplicate bookmark name.
You can also use this section to rename an existing bookmark.
Source Bookmark Tool Add-In
VBA solution
There isn't a rename function. You have to delete the old name and mark the range with a new bookmark name. Here's sample VBA code:
Sub ReNameBookMark()
Dim doc As Word.Document
Dim rng As Word.Range
Dim bmk As Word.Bookmark
Dim inpBookmark, repBookmark, fieldStr As String
Set doc = Word.ActiveDocument
inpBookmark = InputBox("Enter bookmark name that you want to be replaced:", "BookMark Replace")
repBookmark = InputBox("Enter bookmark name replace with:", "BookMark Replace")
Set rng = doc.Bookmarks(inpBookmark).Range
Set bmk = doc.Bookmarks(inpBookmark)
bmk.Delete
rng.Bookmarks.Add (repBookmark)
If doc.Fields.Count >= 1 Then
For i = 1 To doc.Fields.Count
fieldStr = doc.Fields(i).Code.Text
If Left(fieldStr, 4) = " REF" Then
doc.Fields(i).Code.Text = Replace(fieldStr, inpBookmark, repBookmark, , 1, vbTextCompare)
doc.Fields(i).Update
End If
'MsgBox "Code = " & doc.Fields(i).Code & vbCr & "Result = " & doc.Fields(i).Result & vbCr
Next i
End If
End Sub
Source Change the "name" of a bookmark not the text of it, with an additional loop to run through the fields in the document to change any that might be referencing the bookmark being renamed.
Care should be taken using this script. For example renaming any bookmarks that are simply named "REF" (or an upper or lower case variant of such) will break ALL references in amusing and unexpected ways. This is meant as an example and rough fix only.
If you want to batch rename multiple bookmarks in one go see Is there a simpler or more effective way to rename bookmarks in Word documents? which also includes sample VBA code.
I had this same issue and stumbled across this work around/solution.
For the text that you want to reference, a title in my case, set up a Document property title as follows:
Insert tab
→Quick Parts
→Document Property
→Title
This then adds an editable box for text into which you can type your title.
Then, to reference it you could just go to Insert tab
→Quick Parts
→Field
→Title
, or do like what I did accidentally - I had a reference set up and when I updated it with F9 it added the title box that it was referencing.
This is pretty cool since as you update the title box the references all update automatically without pressing F9!!! This is great when you have the reference in a header since the Ctrl+A function does not capture what is in the header/footer and you would usually have to double click inside the header/footer to select, and press F9 to update.
So instead of creating a title reference as stated above do this:
-
After setting up the title box, create a Bookmark of the Title box:
- Select the title box (make sure you click the title tab at the top to select all of the box)
-
Insert
→Bookmark
→(name it sayProject_title
)→add
-
Then add the reference like this:
-
Insert tab
→Quick Parts
→Field
→Ref
(and selectProject_title
or whatever you called it)
-