Name

workbook.ChangeLink(Name, NewName, [Type])

Synopsis

Changes the source of a link.

Argument

Settings

Name

The name of the link to change. Link names are returned by the LinkSources method.

NewName

The source of the new link.

Type

Use xlLinkTypeExcelLinks to change a link from a Microsoft Excel source; use xlLinkTypeOLELinks for an OLE source.

For example, the following code iterates through the Excel links in a workbook and changes links from the test1.xls file to test2.xls:

Dim link, linkSources, newLink As String
newLink = ThisWorkbook.Path & "\test2.xls"
linkSources = ThisWorkbook.linkSources(xlLinkTypeExcelLinks)
If IsArray(linkSources) Then
    For Each link In linkSources
        If InStr(link, "test1.xls") Then _
          ThisWorkbook.ChangeLink link, newLink, xlLinkTypeExcelLinks
    Next
End If

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.