Share via


WorkbookBase.ChangeLink(String, String, XlLinkType) Method

Definition

Changes a link from one document to another.

public void ChangeLink (string name, string newName, Microsoft.Office.Interop.Excel.XlLinkType type);
member this.ChangeLink : string * string * Microsoft.Office.Interop.Excel.XlLinkType -> unit
Public Sub ChangeLink (name As String, newName As String, Optional type As XlLinkType)

Parameters

name
String

The name of the Microsoft Office Excel or DDE/OLE link to be changed, as it was returned from the LinkSources(Object) method.

newName
String

The new name of the link.

type
XlLinkType

One of the XlLinkType values that specifies the link type.

Examples

The following code example creates an external link to an Excel workbook and then uses the ChangeLink method to change the link destination. This example assumes that workbooks Book2.xlsx and Book3.xls exist at the root of the C directory.

This example is for a document-level customization.

private void ChangeAllLinks()
{
    Globals.Sheet1.Range["A1"].FormulaR1C1 =
        @"='C:\[Book2.xlsx]Sheet1'!R2C2";

    this.ChangeLink(@"C:\Book2.xlsx", @"C:\Book3.xlsx",
        Excel.XlLinkType.xlLinkTypeExcelLinks);
}
Private Sub ChangeAllLinks()
    Globals.Sheet1.Range("A1").FormulaR1C1 = _
        "='C:\[Book2.xlsx]Sheet1'!R2C2"

    Me.ChangeLink("C:\Book2.xlsx", "C:\Book3.xlsx", _
        Excel.XlLinkType.xlLinkTypeExcelLinks)
End Sub

Remarks

Optional Parameters

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

Applies to