VBA/Excel/Access/Word/Excel/Worksheet Export Import

Материал из VB Эксперт
Перейти к: навигация, поиск

Adding a Schema to a Workbook

   <source lang="vb">

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

</source>
   
  


Exporting XML

   <source lang="vb">

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

</source>
   
  


Importing an XML Data File

   <source lang="vb">

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

</source>