Option Explicit
Sub ExtracAttributesPathAuto()
Dim objXML As Object, Fichier$, i&, y&, monRepertoire$, dialog As Object, elements, elem
With Sheets("Feuil2")
.Activate
.UsedRange.ClearContents
End With
Set dialog = Application.FileDialog(msoFileDialogFolderPicker)
dialog.Show
If dialog.SelectedItems.Count > 0 Then
monRepertoire = dialog.SelectedItems(1)
Else
MsgBox "Aucun Répertoire Sélectionné": Exit Sub
End If
Cells(1, 1).Resize(, 3).Value = Array("planId", "sessionId", "recordType")
Fichier = Dir(monRepertoire & "\" & "*.xml")
y = 2
Do While Len(Fichier) > 0
Set objXML = CreateObject("MSXML2.DOMDocument")
objXML.async = False: objXML.validateOnParse = False
objXML.Load (monRepertoire & "\" & Fichier)
Set elements = objXML.getelementsbytagname("*")
For Each elem In elements
If Not IsNull(elem.getattribute("planId")) Then Cells(y, 1).Value = elem.getattribute("planId")
If Not IsNull(elem.getattribute("sessionId")) Then Cells(y, 2).Value = elem.getattribute("sessionId")
If Not IsNull(elem.getattribute("recordType")) Then Cells(y, 3).Value = elem.getattribute("recordType")
Next
y = y + 1
Fichier = Dir
Loop
With ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1").Resize(y - 1, 3), , xlYes)
.Name = "Tableau1"
'.TableStyle = "TableStyleLight9"
End With
End Sub