Join TSR now and chat about whatever you’re intoSign up now

change a bookmark name in Word2010 Watch

    • Thread Starter
    Offline

    0
    ReputationRep:
    Hey,

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

    0
    ReputationRep:
    For that , you have two ways to do that.

    M1
    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

    M2
    use VBA

    Code:
    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
 
 
 
Reply
Submit reply
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
Poll
Which web browser do you use?
Useful resources

Articles:

The Student Room tech wikiTech forum guidelines

Quick link:

Unanswered technology and computers threads

Sponsored features:

Web Legend

Win a Macbook Air!

Blog about setting up a website for a chance to win in our Web Legend competition.

Groups associated with this forum:

View associated groups

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

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