Partilhar via


WorkbookBase.ChangeLink Method

Changes a link from one document to another.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Sub ChangeLink ( _
    name As String, _
    newName As String, _
    type As XlLinkType _
)
public void ChangeLink(
    string name,
    string newName,
    XlLinkType type
)

Parameters

  • name
    Type: System.String

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

Remarks

Optional Parameters

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

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 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
private void ChangeAllLinks()
{
    Globals.Sheet1.Range["A1"].FormulaR1C1 =
        @"='C:\[Book2.xlsx]Sheet1'!R2C2";

    this.ChangeLink(@"C:\Book2.xlsx", @"C:\Book3.xlsx",
        Excel.XlLinkType.xlLinkTypeExcelLinks);
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace