VBA/Excel/Access/Word/Excel/Worksheet Export Import
Adding a Schema to a Workbook
Sub ImportXMLSchema()
Dim xmMap As XmlMap
Application.DisplayAlerts = False
Set xmMap = ActiveWorkbook.XmlMaps.add("C:\invoice.xml", "Invoice")
Application.DisplayAlerts = True
xmMap.AdjustColumnWidth = False
xmMap.PreserveNumberFormatting = True
Set xmMap = Nothing
End Sub
Exporting XML
Sub ExportInvoiceXML()
Dim xlMap As XmlMap
Set xlMap = ThisWorkbook.XmlMaps("Invoice_Map")
If xlMap.IsExportable Then
xlMap.Export "C:\testxmljunk.xml"
Else
MsgBox "Sorry, this XML Map is not exportable", vbOKOnly
End If
Set xlMap = Nothing
End Sub
Importing an XML Data File
Sub ImportXMLData()
Dim xlImportResult As XlXmlImportResult
xlImportResult = ThisWorkbook.XmlMaps("Invoice_Map").Import("C:\invoice.xml", True)
Select Case xlImportResult
Case xlXmlImportElementsTruncated
Debug.Print "XML data items imported with truncation."
Case xlXmlImportSuccess
Debug.Print "XML data items imported successfully."
Case xlXmlImportValidationFailed
Debug.Print "XML data items not imported. Validation failed."
Case Else
Debug.Print "Data import process reported an unknown result code."
End Select
Set xlImportResult = Nothing
End Sub