Option Explicit
Private Sub Workbook_Open()
Dim Fso As Object
Dim F_Old, F_New, F_Cur
Set Fso = CreateObject("Scripting.FileSystemObject")
With Worksheets("synthèse")
If InStr(.[B2].Formula, "[") > 2 Then
' Classeur à ouvrir
F_Old = Split(Split(.[B2].Formula, "'")(1), "]")(0)
F_Cur = Replace(F_Old, "[", "")
If Not Fso.FileExists(F_Cur) Then
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "Sélectionner le fichier source"
.AllowMultiSelect = False
.ButtonName = "Sélection Fichier"
With .Filters
.Clear
.Add "Classeur réf", "*.xl*"
End With
If .Show Then F_Cur = .SelectedItems(1) Else F_Cur = ""
End With
End If
If F_Cur <> "" Then
F_New = Fso.GetFile(F_Cur).ParentFolder.Path & "\[" & Fso.GetFile(F_Cur).Name
.Cells.Replace What:=F_Old, Replacement:=F_New, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Workbooks.Open F_Cur, True
End If
ThisWorkbook.Activate
Else
' Classeur déjà ouvert
.Calculate
End If
End With
Set Fso = Nothing
End Sub