Udostępnij za pośrednictwem


Bookmark.InsertCrossReference Method

Inserts a cross-reference to a heading, bookmark, footnote, or endnote, or to an item for which a caption label is defined (for example, an equation, figure, or table) into a Bookmark control.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Sub InsertCrossReference ( _
    ByRef ReferenceType As Object, _
    ReferenceKind As WdReferenceKind, _
    ByRef ReferenceItem As Object, _
    ByRef InsertAsHyperlink As Object, _
    ByRef IncludePosition As Object, _
    ByRef SeparateNumbers As Object, _
    ByRef SeparatorString As Object _
)
void InsertCrossReference(
    ref Object ReferenceType,
    WdReferenceKind ReferenceKind,
    ref Object ReferenceItem,
    ref Object InsertAsHyperlink,
    ref Object IncludePosition,
    ref Object SeparateNumbers,
    ref Object SeparatorString
)

Parameters

  • ReferenceItem
    Type: System.Object%
    If ReferenceType is wdRefTypeBookmark, this argument specifies a bookmark name. For all other ReferenceType values, this argument specifies the item number or name in the Reference type box in the Cross-reference dialog box. Use the GetCrossReferenceItems method to return a list of item names that can be used with this argument.
  • InsertAsHyperlink
    Type: System.Object%
    true to insert the cross-reference as a hyperlink to the referenced item; otherwise, false.
  • IncludePosition
    Type: System.Object%
    true to insert above or below, depending on the location of the reference item in relation to the cross-reference.
  • SeparatorString
    Type: System.Object%
    Specifies the string to use as a separator if the SeparateNumbers parameter is set to true.

Remarks

If you specify wdPageNumber for the value of ReferenceKind, you might need to repaginate the document in order to see the correct cross-reference information.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example adds a heading and text to the document using Bookmark controls and then inserts a cross-reference to the heading text.

This example is for a document-level customization.

Private Sub BookmarkInsertCrossReference()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()

    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")
    Bookmark1.Text = "Heading of Document"
    Bookmark1.Style = "Heading 1"
    Bookmark1.Delete()

    Dim Bookmark2 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(2).Range, "Bookmark2")
    Bookmark2.Text = "This is sample bookmark text: "

    Bookmark2.Words.Last.InsertCrossReference("Heading", _
        Word.WdReferenceKind.wdContentText, "1", True, _
        False, False, " ")

End Sub
private void BookmarkInsertCrossReference()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();

    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "Heading of Document";
    bookmark1.Style = "Heading 1";
    bookmark1.Delete();

    Microsoft.Office.Tools.Word.Bookmark bookmark2 =
        this.Controls.AddBookmark(this.Paragraphs[2].Range,
        "bookmark2");
    bookmark2.Text = "This is sample bookmark text: ";

    object ReferenceType = "Heading";
    object ReferenceItem = "1";
    object InsertAsHyperlink = true;
    object IncludePosition = false;
    object SeparateNumbers = false;
    object SeparatorString = " ";

    bookmark2.Words.Last.InsertCrossReference(ref ReferenceType,
        Word.WdReferenceKind.wdContentText, ref ReferenceItem, 
        ref InsertAsHyperlink, ref IncludePosition,
        ref SeparateNumbers, ref SeparatorString);
}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace