Hey there! Sign in to join this conversationNew here? Join for free
x Turn on thread page Beta
    • Thread Starter


    I'm working with my paper. Every thing is fine until I find I just add a bookmark with wrong name.

    I can delete it and create it again with the new name. But there are quite a few
    cross-references to this bookmark. They will be all failed with error if I delete the bookmark. God, do I have to set all cross-references again?

    Is there any way that I can just change the bookmark name and auto update all
    cross-references to the new bookmark? Thanks in advance.

    For that , you have two ways to do that.

    1. Change the bookmark name from A to B
    2. Press “Alt+ F9” to show the field codes
    3. Open “Find and Replace” dialog box. enter “REF A ” in “Find what” enter “REF B” in “Find what” , click “Replace All"
    4. update all fields in the document

    use VBA

    Sub ChangeTheBookMarkNameAndUpdateCrossReference()  Dim strBookMarkName As String  Dim strNewName As String  Dim objBookMarkRange As Range  Dim objField As Field  Dim strFieldCode As String   '  Rename the bookmark name.  strBookMarkName = InputBox("Enter the bookmark name which you want to change", "BookMark Name", "For example: DWORDR")  strNewName = InputBox("Enter the New bookmark Name", "New Bookmark Name", "For example: New text")   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            MsgBox ("Code = " & objField.Code & vbCr & "Result = " & objField.Result & vbCr)          End If         Next objField       End If    Else      MsgBox ("The Bookmark: " & strBookMarkName & " is not founded.")    End If  End With   Set objBookMarkRange = NothingEnd Sub
    Hope it helps
Submit reply
Turn on thread page Beta
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: May 23, 2017
What's the best type of cheese?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.