I was hoping to see your code so I could provide a very specific solution. Such as it is, I will provide a general solution.
This assumes that the file you are referencing is in the same folder as the file you are referencing it from. It puts an error message instead of a link if the file is not found.
Dim fileName As String
Dim ref As Range
' Full reference is in B1
' It should look just like it would appear in a formula:
' '[external referencedx.xlsx]Sheet1'!$A$1
Set ref = Range("B1")
' Get the file name from the cell
fileName = Mid(ref, InStr(1, ref, "[") + 1, InStr(1, ref, "]") - InStr(1, ref, "[") - 1)
' Does the file exist?
If Dir(ThisWorkbook.Path & "\" & fileName) <> "" Then
' You have to add the single quote after the "=" because
' when you include it in the cell text, Excel interprets it as a
' flag to treat the cell as text, and does not return it as
' part of the cell's value
Range("A1").Formula = "='" & Range("B1")
Else
Range("A1") = "NOT FOUND!"
End If
Bookmarks