Created
June 14, 2018 13:41
-
-
Save hedgejanuary/0c7689ba78722d4bce3720f68b635def to your computer and use it in GitHub Desktop.
Check if the file has the external links and list them in the first sheet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ListLinks() | |
Dim ws As Worksheet | |
Dim rFormulas As Range | |
Dim rCell As Range | |
Dim aLinks() As String | |
Dim i As Long | |
If ThisWorkbook Is Nothing Then Exit Sub | |
i = 0 | |
For Each ws In ThisWorkbook.Worksheets | |
On Error Resume Next | |
Set rFormulas = ws.UsedRange.SpecialCells(xlCellTypeFormulas) | |
On Error GoTo 0 | |
If Not rFormulas Is Nothing Then | |
For Each rCell In rFormulas | |
If InStr(1, rCell.Formula, "[") > 0 Then | |
i = i + 1 | |
ReDim Preserve aLinks(1 To 2, 1 To i) | |
aLinks(1, i) = rCell.Address(, , , True) | |
aLinks(2, i) = "'" & rCell.Formula | |
End If | |
Next rCell | |
End If | |
Next ws | |
If i > 0 Then | |
Worksheets.Add before:=Worksheets(1) | |
Range("A1").Resize(, 2).Value = Array("Location", "Reference") | |
Range("A2").Resize(UBound(aLinks, 2), UBound(aLinks, 1)).Value = Application.Transpose(aLinks) | |
Columns("A:B").AutoFit | |
Else | |
MsgBox "No links were found within the active workbook.", vbInformation | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment