Sub test()
Dim sfolder$, fichier, header$, y&, file$
fichier = ThisWorkbook.Path & "\compilation.csv"
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then ' if OK is pressed
sfolder = .SelectedItems(1)
Else: Exit Sub
End If
End With
header = "NumeroCient;NumeroContrat;NumeroSinistre;Identifiant Unique document;Code Maquette;Date de creation Document;Civilité;Nom;Prenom;" & _
"branche;famille;Sous famille;Sous Famille2;Libellé Produit;Univers;sendflux;sourceged;libelléstatut;docencrys;" & _
"IDAQUISIT;IDAQUISIT;IDAQUISIT;Chemin d'acces au fichier"
y = FreeFile: Open fichier For Output As #y: Print #y, header: Close #y
NbCol = UBound(Split(header, ";"))
file = Dir(sfolder & "\*.xml")
Do While file <> ""
ok = mangetout(sfolder & "\" & file, fichier, NbCol)
' MsgBox file
Do While a = 500: DoEvents: a = a + 1: Loop
DoEvents
file = Dir()
Loop
MsgBox "votre compilation en csv est prête "
End Sub
Function mangetout(myfile, compilcsv, NbCol)
Dim T, NodeDoc, Nodexs As Object, x&, header, tabhead, tb$(), i
With CreateObject("microsoft.xmldom")
.Load myfile
Set NodeDoc = .getelementsbytagname("Document")
For i = 0 To NodeDoc.Length - 1
ReDim tb(NbCol) ' t = t & Nodexs(i).Text & ":" & vbTab & Nodexs(i).NextSibling.Text & vbCrLf
tb(UBound(tb)) = NodeDoc(i).ChildNodes(0).Text
Set Nodexs = NodeDoc(i).getelementsbytagname("Name")
For a = 0 To Nodexs.Length - 1
Select Case Nodexs(a).Text
Case "datedoc": tb(5) = Nodexs(a).NextSibling.Text
Case "numadh": tb(1) = Nodexs(a).NextSibling.Text
Case "numcli": tb(0) = Nodexs(a).NextSibling.Text
Case "cciv": tb(6) = Nodexs(a).NextSibling.Text
Case "nom1": tb(8) = Nodexs(a).NextSibling.Text
Case "nom2": tb(7) = Nodexs(a).NextSibling.Text
Case "cetat": tb(4) = Nodexs(a).NextSibling.Text
End Select
Next
T = T & Join(tb, ";") & IIf(i < NodeDoc.Length - 1, vbCrLf, "")
Next
End With
x = FreeFile: Open compilcsv For Append As #x: Print #x, T: Close #x
mangetout = True
End Function