12

I often use bookmarks in Word in order to create technical documents with internal links to citations and commonly used information that needs to be consistent throughout the document. You can create them by selecting the text and then going to the menu Insert -> Links -> Bookmark and assigning a name, then going to Insert -> Links -> Citations and selecting the bookmark to insert. This will then insert the text of that bookmark elsewhere in the document.

As an example of why I do this: I often have a front page listing the document state and that information is then repeated in the footer, using a bookmark I can set up a link to that text and then simply insert that link in the footer and it will update automatically whenever I go to the print preview or update all fields in the document. This way I can avoid doing a search and replace and just know that the correct text will be updated in the correct places.

enter image description here

Now lets say I have a bookmark that I've just roughly named, just to get it into place:
enter image description here

There is no right-click to rename a bookmark and I cannot find any document property that will let me amend it.

I am able to insert a NEW bookmark by selecting the same text and then deleting the old one but then you get this:
enter image description here

You then have to right click the field and point it back at the (now effectively renamed) bookmark.

This isn't completely usable, especially in a large document where this bookmark is used multiple times.

I have Googled around and seen several VBA scripts on the web such as in this question but as they effectively create a new boomark and delete the old one they create the same problem as above and are less than ideal.

Is there a simpler or more effective way to rename bookmarks in Word documents? Or am I possibly using the Wrong Tool™ for this job?

3
  • Did you mean Word 2013, instead of 2010?
    – user269574
    Sep 4, 2015 at 2:28
  • @LePressentiment my copy of Word is 2010, but I don't see why the answer below would not apply to 2013 unless they have significantly overhauled the bookmarking feature between versions. I'd actually be surprised if they had.
    – Mokubai
    Sep 4, 2015 at 6:43
  • @LePressentiment See my answer that has been updated by Mokubai.
    – DavidPostill
    Sep 4, 2015 at 14:37

3 Answers 3

7

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:

  1. Use an Add-in.

  2. 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.

    enter image description here

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.

4
  • @Mokubai It looks like you may be able to do this with the Add-in (see updated answer)? Unfortunately I don't have a copy of Word to test with...
    – DavidPostill
    Sep 3, 2015 at 22:16
  • I'll give the addin a test in the morning when I get back to my PC. It's probably fine for home, but at work I don't think I'll be able to use it as our IT department can be a bit wary of that sort of thing. I'll try both methods and see if I can enhance your VBA script to do the search and replace. If I get somewhere and it's okay with you I'd like to edit it into your answer.
    – Mokubai
    Sep 3, 2015 at 22:27
  • @LePressentiment In case it is any help for what you want, I have added some features to the VBA script above to give you an input box for current and new names, and done a dirty search and replace in fields that refer to those bookmarks. It's not perfect, but it's better than nothing and will more than suit what I need to do at work.
    – Mokubai
    Sep 4, 2015 at 13:59
  • The Bookmark Tool Add-in breaks references to bookmarks after renaming them (for me in Word 365 on Windows).
    – filups21
    Jan 16, 2020 at 14:57
1

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 tabQuick PartsDocument PropertyTitle

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 tabQuick PartsFieldTitle, 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)
    • InsertBookmark→(name it say Project_title)→add
  • Then add the reference like this:

    • Insert tabQuick PartsFieldRef (and select Project_title or whatever you called it)
0

David Postill's vba code above captures the gist, but misses one thing: It will fix the references in the main body of the doc, but NOT any references that hide in the headers or footers. See the code I posted in response to a similar question, here: https://superuser.com/a/1612677/881187

It offers batch renaming of bookmarks including options to work on the entire doc or on a selection, and to rename groups of bookmarks based on their prefixes. It then also amends all the references, all of the doc, including in headers and footers.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .