InsertCrossReference Method
Applies To
Range object, Selection object.
Description
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).
Syntax
expression.InsertCrossReference(ReferenceType, ReferenceKind, ReferenceItem,
ú InsertAsHyperLink, IncludePosition)
expression Required. An expression that returns a Range or Selection object.
ReferenceType Required Variant. The type of item for which a cross-reference is to be inserted. Can be one of the following WdReferenceType constants: wdRefTypeBookmark, wdRefTypeEndnote, wdRefTypeFootnote, wdRefTypeHeading, or wdRefTypeNumberedItem. Can also be a WdCaptionLabelID constant (wdCaptionEquation, wdCaptionFigure, or wdCaptionTable) or a user defined caption label.
ReferenceKind Required Long. The information to be included in the cross-reference. Can be one of the following WdReferenceKind constants: wdContentText, wdEndnoteNumber, wdEndnoteNumberFormatted, wdEntireCaption, wdFootnoteNumber, wdFootnoteNumberFormatted, wdNumberFullContext, wdNumberNoContext, wdNumberRelativeContext, wdOnlyCaptionText, wdOnlyLabelAndNumber, wdPageNumber, or wdPosition.
ReferenceItem Required Variant. 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 Optional Variant. True to insert the cross-reference as a hyperlink to the referenced item.
IncludePosition Optional Variant. True to insert "above" or "below," depending on the location of the reference item in relation to the cross-reference.
See Also
GetCrossReferenceItems method, InsertCaption method.
Example
This example inserts at the beginning of the active document a cross-reference to the page that includes the first bookmark in the document.
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
myBookmarks = ActiveDocument.GetCrossReferenceItems(wdRefTypeBookmark)
With myRange
.InsertBefore "Page "
.Collapse Direction:=wdCollapseEnd
.InsertCrossReference ReferenceType:=wdRefTypeBookmark, _
ReferenceKind:=wdPageNumber, ReferenceItem:=myBookmarks(1)
End With
This example inserts a sentence that contains two cross-references: one cross-reference to heading text, and another one to the page where the heading text appears.
With Selection
.Collapse Direction:=wdCollapseStart
.InsertBefore "For more information, see "
.Collapse Direction:=wdCollapseEnd
.InsertCrossReference ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdContentText, ReferenceItem:=1
.InsertAfter " on page "
.Collapse Direction:=wdCollapseEnd
.InsertCrossReference ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdPageNumber, ReferenceItem:=1
.InsertAfter "."
End With