How to find the location of a link in an Excel workbook?
I have an Excel workbook that, when opened, gives a warning:
This workbook contains links to other data sources.
I want to remove all these links so that the alert does not fire. I think any external link will look like '[workbook path]'!address
I used this code:
Sub ListLinks()
Dim wb As Workbook
Dim link As Variant
Set wb = ThisWorkbook
For Each link In wb.LinkSources(xlExcelLinks)
Debug.Print link
Next link
End Sub
This returns the path to the file:
\\somePath\xyz\aWorkbook.xlsm
I searched all the formulas in the book for this line using Ctrl + F, but no results were returned. How do I find and remove this link?
+3
source to share
4 answers
The next cycle should work.
Dim intCounter As Integer
Dim varLink As Variant
'Define variable as an Excel link type.
varLink = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
'Are there any links?
If IsArray(varLink) = False Then
Exit Sub
End If
'Break the links in the active workbook.
For intCounter = 1 To UBound(varLink)
ActiveWorkbook.BreakLink _
Name:=varLink(intCounter), _
Type:=xlLinkTypeExcelLinks
Next intCounter
+1
source to share