none
Creating Index Entry with field inside of it in Word 2010 VSTO RRS feed

  • Question

  • Hi

    I'm trying to make a button where you can mark index entries. It should then add the selected text and the text of a bookmark instead of the page number.

    I have a problem with making the reference to an existing bookmark. I have tried different approaches but it ends with 2 scenarios either the index entry is replaced with the field or the name of the bookmark is shown as plain text.

    This is the code that I'm using right now. "side" is the name of the bookmark and the bookmark since I'm using it in other fields.

    I have also tried Bookmark and CrossReferenceAutoText instead of CrossReference with no luck.

    var selectedText = Application.Selection.Text;
    var selectedRange = Application.Selection.Range;
    Application.ActiveDocument.Indexes.MarkEntry(selectedRange, selectedText,CrossReference: "side");

    The output I get if I select the word "Text":

    {XE "Text" \t "side"}

    Instead of the word "side" there should be a field that shows the value of the bookmark called "side"

    How do I accomplish this?


    • Edited by m_plh Wednesday, August 14, 2013 12:10 PM
    Wednesday, August 14, 2013 9:29 AM

All replies

  • Hello,

    Appliation.ActiveDocument.Indexes.MarkEntry(Range:=Selection.Range, Entry:=Abbreviation, CrossReference:=Definition, CrossReferenceAutoText:="", BookmarkName:="side", Bold:=False, Italic:=False)

    Something like this?


    Best Regards,
    A Beginner :)
    Please remember to mark the replies as answers if they help

    • Edited by IssueKiller Saturday, August 24, 2013 10:10 AM
    Saturday, August 24, 2013 10:10 AM

  • Hi,

    After you did markEntry, the index was already added in the document as it show:

    {XE "Text" \t "side"}

    And the property of "ActiveWindow.ActivePane.View.ShowAll" will be set to true.

    You can set the property to false like code below:

    ActiveWindow.ActivePane.View.ShowAll=false;

    Saturday, August 24, 2013 11:21 AM
  • You're using the wrong field. You don't want to mark an Index entry if you want to display the content of a bookmark. You need to insert a cross-reference (a REF field): { REF side }.

    Inserting an XE field will display the term "Text" in an index you later insert into the document.


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, August 24, 2013 3:22 PM
    Moderator