I have try code given below
Sub Btn_export()
Dim strName As String
Dim BigRange As Range
Dim oMyMap As XmlMap
'Dim strXPath As String
Dim oMyNewColumn As ListColumn
Dim myxmlmap As XmlMap
Dim myXMLSchemaString As String
Dim oMyList As ListObject
Dim Range1 As Range
Dim Sheet1 As Worksheet
Dim mapContact As XmlMap
Dim strXPath As String
Dim lstContacts As ListObject
Dim objNewCol As ListColumn
On Error GoTo ErrorHandler
'Fill the excel with data. For Test.
'You can delete it if you have a exist excel
Set Sheet1 = ThisWorkbook.Sheets("Menu")
For Each currentMap In ActiveWorkbook.XmlMaps
If currentMap.Name = "TKPlusIAR_Map" Then
ActiveWorkbook.XmlMaps("TKPlusIAR_Map").Delete
End If
Next
'Load Schema
ThisWorkbook.XmlMaps.Add ("D:\solpm\tkplusIAR.xsd")
Set oMyMap = ThisWorkbook.XmlMaps("TKPlusIAR_Map")
With oMyMap
.PreserveColumnFilter = False
.PreserveNumberFormatting = True
.AdjustColumnWidth = False
End With
'Set ListObject
Set Range1 = Sheet1.Range("_Ref_Mois:_Ref_Mois")
Range1.Select
Set oMyList = Sheet1.ListObjects.Add
' From a List
'Map the first element
strXPath = "/ns1:TKPlusIAR/ns1:info/ns1:moisCourant"
'Map the element.
oMyList.ListColumns(1).XPath.SetValue oMyMap, strXPath
'Add a new column
'Set oMyNewColumn = oMyList.ListColumns(2)
'strXPath = "/ns1:TKPlusIAR/ns1:info/ns1:devise"
'oMyList.ListColumns(2).XPath.SetValue oMyMap, strXPath
'Add a new column
'Set oMyNewColumn = oMyList.ListColumns(3)
'strXPath = "/ns1:TKPlusIAR/ns1:info/ns1:agence"
'oMyList.ListColumns(3).XPath.SetValue oMyMap, strXPath
'Add a new column
'Set oMyNewColumn = oMyList.ListColumns(4)
'strXPath = "/ns1:TKPlusIAR/ns1:info/ns1:client"
'oMyList.ListColumns(4).XPath.SetValue oMyMap, strXPath
'oMyList.ListColumns(1).Name = "Mois courant"
' Export the xml file
'ThisWorkbook.XML
'ThisWorkbook.XmlMaps.IsExportable
ThisWorkbook.XmlMaps("TKPlusIAR_Map").Export URL:="D:\IAR.xml"
Exit Sub
ErrorHandler:
'show the error with a pop up
'Err is your error
MsgBox "There is an error: " & Err.Number & vbCrLf & Err.Description
'some code to continue
If i = 0 Then i = 1
Resume
End Sub
but it show me error like
The map could not be exported, so the data was not
exported
with error code -2147217406
for reference i am using xml schema like
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="TKPlusIAR" type="tns:TKPlusIARDefinition"/>
<xs:complexType name="TKPlusIARDefinition">
<xs:sequence>
<xs:element name="info" type="tns:infoDefinition" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="infoDefinition">
<xs:sequence>
<xs:element name="moisCourant" type="tns:monthYear" />
<xs:element name="devise" type="xs:string" />
<xs:element name="agence" type="xs:string" />
<xs:element name="client" type="xs:string" />
<xs:element name="iterationInfo">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="code" />
<xs:element type="xs:string" name="num" />
<xs:element type="xs:date" name="debut" />
<xs:element type="xs:date" name="fin" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<!-- ==================================================== -->
<!-- === Formats === -->
<!-- ==================================================== -->
<!-- MoisAnnee MM-YYYY -->
<xs:simpleType name="monthYear">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}-[0-9]{4}" />
</xs:restriction>
</xs:simpleType>
<!-- Annee YYYY -->
<xs:simpleType name="year">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{4}" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
Bookmarks