Private Sub CommandButton3_Click()
Dim t, wbDest As Workbook, myPath$, w As Worksheet, myFile$, mySheetName$
t = Timer
Set wbDest = ThisWorkbook
'myPath = "D:\Lycée Stéphane Hessel\OneDrive - Lycée Stéphane Hessel\Karl EPS\Protocoles BGT BCP CAP 23\Import Fichiers Santorin\"
myPath = wbDest.Path & "\"
myFile = Dir(myPath & "*.csv")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'---suppression des feuilles créées précédemment---
For Each w In wbDest.Worksheets
If w.QueryTables.Count Then w.Delete
Next w
'---création des feuilles---
Do While myFile <> ""
mySheetName = Left(myFile, Len(myFile) - 4)
With wbDest
.Activate
On Error Resume Next
.Sheets(mySheetName).Delete 'au cas où...
On Error GoTo 0
.Sheets.Add After:=.Sheets(.Sheets.Count)
ActiveSheet.Name = mySheetName
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & myPath & myFile, Destination:=ActiveSheet.Cells(1))
.TextFileParseType = xlDelimited
.TextFileSemicolonDelimiter = True
.Refresh
End With
End With
myFile = Dir
Loop
wbDest.Sheets(1).Activate
MsgBox "Durée " & Format(Timer - t, "0.00 \sec")
End Sub