Creating a Custom XML List : ListObject « File Path « VBA / Excel / Access / Word






Creating a Custom XML List

 
     Sub CreateXMLList()
         Dim oMyMap As XmlMap
         Dim strXPath As String
         Dim oMyList As ListObject
         Dim oMyNewColumn As ListColumn
         ThisWorkbook.XmlMaps.Add (ThisWorkbook.Path & "\Myschema.xsd")
         Set oMyMap = ThisWorkbook.XmlMaps("EmployeeSales_Map")
         Range("A1").Select
         Set oMyList = ActiveSheet.ListObjects.Add
         strXPath = "/EmployeeSales/Employee/Empid"
         oMyList.ListColumns(1).XPath.SetValue oMyMap, strXPath
         Set oMyNewColumn = oMyList.ListColumns.Add
         strXPath = "/EmployeeSales/Employee/InvoiceNumber"
         oMyNewColumn.XPath.SetValue oMyMap, strXPath
         Set oMyNewColumn = oMyList.ListColumns.Add
         strXPath = "/EmployeeSales/Employee/InvoiceAmount"
         oMyNewColumn.XPath.SetValue oMyMap, strXPath
         oMyList.ListColumns(1).Name = "EmployeeId"
         oMyList.ListColumns(2).Name = "Invoice Number"
         oMyList.ListColumns(3).Name = "Invoice Amount"
     End Sub

 








Related examples in the same category

1.Inspecting a ListObject
2.To create a table from cells A1:F6, and assuming the table has column headers