1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Option Explicit
Option Base 1
Sub TableauExcel_XML_V01()
Dim xmlDoc As MSXML2.DOMDocument
Dim xmLstring As String, Fichier As String, strQuote As String
Dim Lig As Integer, Col As Integer
Dim Attribut As Variant
strQuote = """"
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmLstring = "<?xml version=""1.0"" encoding=""ISO-8859-1"" ?> "
xmLstring = xmLstring & "<FORM Name=" & strQuote _
& "Test Tableau Excel vers xml" & strQuote & "> "
Attribut = Array("Id", "Nom", "Date", "Type", "Url", "Adresse")
For Lig = 1 To 20 ' le tableau Excel contient 20 lignes (1 à 20)
xmLstring = xmLstring & "<CATEGORIE "
For Col = 1 To 6 'le Tableau Excel contient 6 colonnes (A à F)
xmLstring = xmLstring & Attribut(Col) & "=" & _
strQuote & Cells(Lig, Col) & strQuote & " "
Next
xmLstring = xmLstring & "></CATEGORIE>"
Next Lig
xmLstring = xmLstring & "</FORM>"
xmlDoc.loadXML xmLstring 'charger le fichier pour pouvoir l'enregistrer
Fichier = "C:\testExcel_XML.xml"
xmlDoc.Save (Fichier) 'Sauvegarder le fichier xml
End Sub |
Partager