Sub convertxml()
Dim xmldoc As Object, oCreation As Object, lig&, Racine As Object, tableau As Object, c&, a As Object, m As Object
Dim head As Range, rang As Range, period As Object, X&, Fichier$
Set xmldoc = CreateObject("Microsoft.XMLDOM") 'creation
Set Racine = xmldoc.createelement("mouvements-balances") 'ajout de la racine "kml"
Racine.setattribute "xmlns", "http://douane.finances.gouv.fr/app/ciel/dtiplus/v1"
xmldoc.appendchild Racine 'insertion dans le document (append) de kml
Set oCreation = xmldoc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'") 'creation de l'entete du process
xmldoc.InsertBefore oCreation, xmldoc.ChildNodes.Item(0) 'insertion parametre process
Set period = xmldoc.createelement("periode-taxation") 'ajout de la racine "kml"
Racine.appendchild period 'insertion dans le document (append) de kml
Set head = Feuil1.ListObjects("Tableau3").HeaderRowRange
Set structab = Feuil1.ListObjects("Tableau3").DataBodyRange
Set m = xmldoc.createelement("mois"): m.Text = structab.Cells(1, 1).Text: period.appendchild m
Set a = xmldoc.createelement("Annee"): a.Text = structab.Cells(1, 2).Text: period.appendchild a
Set identredev = xmldoc.createelement("identification-redevable"): identredev.Text = structab.Cells(1, 3).Text
Racine.appendchild identredev
Set head = Feuil1.ListObjects("Tableau3").HeaderRowRange
Set rang = Feuil1.ListObjects("Tableau3").DataBodyRange
For lig = 1 To rang.Cells(rang.Cells.Count).Row - 1
Set prod = xmldoc.createelement("produit"):
identredev.appendchild prod
For c = 4 To head.Cells(rang.Cells.Count).Column
Set bal = xmldoc.createelement(Replace(head.Cells(c).Value, "ns1:", "")): bal.Text = rang.Cells(lig, c).Text
prod.appendchild bal
Next
Next
Fichier = Environ("userprofile") & "\Desktop\sortie.xml"
X = FreeFile
Open Fichier For Output As #X: Print #X, Replace(xmldoc.XML, "><", ">" & vbCrLf & "<"): Close #X
With CreateObject("internetexplorer.application")
.navigate Fichier
.Visible = True
End With
Debug.Print Replace(xmldoc.XML, "><", ">" & vbCrLf & "<")
End Sub