Private Sub CommandButton1_Click()
Dim FolderName$, MyPath, wkbSource As Workbook
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
FolderName = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
MyPath = FolderName
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
'Boucle sur l'ensemble des fichiers du répertoire
MyFile = Dir(MyPath & "*.xl?")
Application.DisplayAlerts = False
Do While Len(MyFile) > 0
Set wkbSource = Workbooks.Open(MyPath & MyFile)
'Avec le classeur ouvert ou qu'on vient d'ouvrir...
With wkbSource
On Error Resume Next
'-> suppression des lignes 1 à 12
.Sheets(1).Range("1:12").EntireRow.Delete
' idée de formule pour insérer le total, deux lignes au dessus de la cellule "extraction" qui n'est pas toujours en ligne 35
.Sheets(1).Cells.Find("Extraction", , xlValues, xlPart).Activate
.Sheets(1).Cells.Offset(-2, 0) = "TOTAL"
'ligne que j'ai remplacé pour contourner la variable de ligne 34 à 37
.Sheets(1).Columns("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
.Sheets(1).Columns("D:G").Delete Shift:=xlToLeft
.Sheets(1).[A1].CurrentRegion.Replace What:=".", Replacement:="0", LookAt:=2
'conversion en fichier CSV
.SaveAs MyPath & VBA.Left(.Name, InStr(.Name, ".") - 1), FileFormat:=xlCSV, Local:=True
.Close savechanges:=False
End With
Set wkbSource = Nothing
'Et on passe au suivant
MyFile = Dir()
Loop
End Sub