如何快速找到引用了外部链接的单元格所在位置
按 Alt+F11 打开 VBA 编辑器,插入模块并运行以下代码,会在新工作表列出所有外部链接的工作表、单元格、公式。
Sub ListExternalLinks()
Dim ws As Worksheet, cell As Range, linkCell As Range
Dim newWS As Worksheet, i As Integer
Set newWS = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
newWS.Name = "外部链接清单"
newWS.Range("A1:C1") = Array("工作表", "单元格", "链接公式")
i = 2
For Each ws In ThisWorkbook.Worksheets
For Each cell In ws.UsedRange
If cell.HasFormula Then
If InStr(1, cell.Formula, "[") > 0 Or InStr(1, cell.Formula, ".xls") > 0 Then
newWS.Cells(i, 1) = ws.Name
newWS.Cells(i, 2) = cell.Address
newWS.Cells(i, 3) = cell.Formula
i = i + 1
End If
End If
Next cell
Next ws
newWS.Columns("A:C").AutoFit
End Sub