'Const oldChaine As String = "Mois,Lieu,Article,Quantités,Montant,Code"
Const oldChaine As String = "Mois,Lieu,Article,Quantités,Montant,Code" 'encodé udf-8
Const NewChaine As String = "Date,Ville,Marchandise,Quantités,Vente,Référence"
Sub test()
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then dossier = .SelectedItems(1)
If dossier = "" Then Exit Sub
End With
replaceAllCsvHeader dossier
End Sub
Function replaceAllCsvHeader(dossier)
Dim FsO As Object, fich, x&, subdossier, contenu As String
Set FsO = CreateObject("Scripting.FileSystemObject")
Set dossier = FsO.GetFolder(dossier)
For Each fich In dossier.Files
'lecture
x = FreeFile: Open fich For Binary Access Read As #x: contenu = String(LOF(x), " "): Get #x, , contenu: Close #x
DoEvents
'ecriture
x = FreeFile: Open fich For Output As #x: Print #x, Replace(contenu, oldChaine, NewChaine): Close #x
Next
For Each subdossier In dossier.subfolders
replaceAllCsvHeader subdossier.Path
Next subdossier
Set FsO = Nothing
msgbox" Remplacement du Header dans les CSVs terminé"
End Function