Sub Envois_Données_Bilan()
Dim Target_Actif As Boolean
Dim Target_Name As String
' On détermine le fichier cible
Target_Name = "G:\Mon Drive\Ete 2025\Bus\Bus Bilan 2025.xlsx"
' On regarde si la cible est déjà active
Dim Wn As Variant
For Each Wn In Windows
If Wn.Caption = Target_Name Then
Target_Actif = True
Exit For
End If
Next
' la cible n'est pas active,
' si elle existe dans le dossier de ce classeur, on l'ouvre
If Not Target_Actif Then
Dim Fso: Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Fname As String: Fname = ThisWorkbook.Path & "\" & Target_Name
If Fso.FileExists(Fname) Then
Workbooks.Open Fname
Target_Actif = True
End If
End If
' la cible n'est toujours pas active,
' on demande la cible à ouvrir
If Not Target_Actif Then
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.InitialFileName = Fname
If .Show Then
Workbooks.Open .SelectedItems(1)
Target_Name = ActiveWindow.Caption
Target_Actif = True
End If
End With
End If
' La cible est active, on peut copier
If Target_Actif Then
Dim I As Integer
Dim Plage As Range: Set Plage = ThisWorkbook.ActiveSheet.Range("L22:P30")
With ThisWorkbook.ActiveSheet.Outline
.ShowLevels RowLevels:=0, ColumnLevels:=1
.ShowLevels RowLevels:=0, ColumnLevels:=2
.ShowLevels RowLevels:=1
.ShowLevels RowLevels:=2
End With
With Windows(Target_Name).Activate
For I = 1 To Plage.Rows.Count
Range("A2").ListObject.ListRows.Add I
Next
Plage.Copy
Range("A2").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
ThisWorkbook.Activate
End If
End Sub