none
Bookmark - find out if it is referenced RRS feed

  • Question

  • Hello community!

    I am working on a project where a Word template is going to be filled with information from C#. I have already achieved most of the functionality, but I am wondering if there is a built in feature in Word to find out where a certain bookmark is referenced.

    Example: DocumentTitle - I know that this bookmark is referenced in the page headers. But are there other references which I have not found til now?

    Thank you for your help
    Best Regards

    Alex

    Thursday, April 23, 2015 6:23 AM

Answers

  • Hi Alex,

    For this requirement, as far as I know there isn’t the built in feature in the word to find out where a certain bookmark is referenced.

    You could get the references (e.g. cross-reference, hyper-link), then iterate these references to check bookmarks.

    For example, to get the cross-reference items that reference to the bookmark, we could use the code of ActiveDocument.GetCrossReferenceItems(wdRefTypeBookmark).

    Simple code to iterate cross-reference items:

    If ActiveDocument.Bookmarks.Count >= 1 Then
        myBookmarks = ActiveDocument.GetCrossReferenceItems( _
            wdRefTypeBookmark)
        For i = 1 To UBound(myBookmarks)
         'MsgBox myBookmarks(i)
         ActiveDocument.Bookmarks(myBookmarks(i)).Select
        Next i
      
    End If

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 24, 2015 3:01 AM
    Moderator

All replies

  • Hi Alex,

    Here is a reference I found that use frequently when working with Word and c# - it is a great resource.

    http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx


    Jo Crews

    Thursday, April 23, 2015 3:35 PM
  • Hi Alex,

    For this requirement, as far as I know there isn’t the built in feature in the word to find out where a certain bookmark is referenced.

    You could get the references (e.g. cross-reference, hyper-link), then iterate these references to check bookmarks.

    For example, to get the cross-reference items that reference to the bookmark, we could use the code of ActiveDocument.GetCrossReferenceItems(wdRefTypeBookmark).

    Simple code to iterate cross-reference items:

    If ActiveDocument.Bookmarks.Count >= 1 Then
        myBookmarks = ActiveDocument.GetCrossReferenceItems( _
            wdRefTypeBookmark)
        For i = 1 To UBound(myBookmarks)
         'MsgBox myBookmarks(i)
         ActiveDocument.Bookmarks(myBookmarks(i)).Select
        Next i
      
    End If

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 24, 2015 3:01 AM
    Moderator