Sub Liens()
Dim w As Worksheet, c As Range, n&, a$(), L, i&, d As Object, wb As Workbook
'---liste des formules de liaison---
For Each w In ThisWorkbook.Worksheets
For Each c In w.UsedRange
If c.HasFormula Then
If InStr(c.Formula, "[") Then
n = n + 1
ReDim Preserve a(1 To 2, 1 To n)
a(1, n) = c.FormulaR1C1
End If
End If
Next
Next
'---ouverture des fichiers sources---
Application.ScreenUpdating = False
L = ThisWorkbook.LinkSources
For i = 1 To UBound(L)
On Error Resume Next
Workbooks.Open(L(i))
If Err Then MsgBox "'" & L(i) & "' introuvable..."
On Error GoTo 0
Next
'---nouvelle liste des formules de liaison---
n = 0
For Each w In ThisWorkbook.Worksheets
For Each c In w.UsedRange
If c.HasFormula Then
If InStr(c.Formula, "[") Then
n = n + 1
a(2, n) = c.FormulaR1C1
End If
End If
Next
Next
'---restitution dans un nouveau document---
Set w = Workbooks.Add.Sheets(1)
w.[A:B].NumberFormat = "@" 'format Texte
w.[A1:B1].Font.Bold = True
w.[A1] = "Formule avant ouverture"
w.[B1] = "Formule après ouverture"
i = 2
Set d = CreateObject("Scripting.Dictionary")
For n = 1 To n
If Not d.exists(a(1, n)) Then 'évite les doublons
d(a(1, n)) = ""
If InStr(a(2, n), "]#REF") Then
w.Cells(i, 1) = a(1, n)
w.Cells(i, 2) = a(2, n)
i = i + 1
End If
End If
Next
w.Columns.AutoFit
'---fermeture des fichiers---
For Each wb In Workbooks
If wb.Name <> w.Parent.Name And wb.Name <> ThisWorkbook.Name _
Then wb.Close False
Next
ThisWorkbook.Close False 'on le ferme aussi...
End Sub