VBA/Excel/Access/Word/Excel/Worksheet Export Import — различия между версиями

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

Версия 16:33, 26 мая 2010

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