+ Reply to Thread
Results 1 to 2 of 2

map xml xsd to excel and export data into xml by vba

Hybrid View

vasudaa map xml xsd to excel and... 07-28-2014, 08:20 AM
vasudaa Re: map xml xsd to excel and... 09-04-2014, 06:06 AM
  1. #1
    Registered User
    Join Date
    07-28-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    2

    map xml xsd to excel and export data into xml by vba

    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>

  2. #2
    Registered User
    Join Date
    07-28-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    2

    Re: map xml xsd to excel and export data into xml by vba

    problem resolved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Export CSV data to Excel Userform using reference number to specify relevant data
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 06-20-2014, 05:41 PM
  2. I would need a macro to export data from base example workbook to export worbook
    By slato8 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 11:21 AM
  3. Excel data (sheet data + charts) export to ppt presentation
    By pntuehut99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2012, 05:55 AM
  4. Replies: 0
    Last Post: 10-14-2010, 08:22 AM
  5. export data from excel using VBA
    By rocket in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1