簡體   English   中英

使用VBA通過xslt轉換文件將XML導入MS Access

[英]Using VBA to Import XML into MS Access with xslt transform file

我正在嘗試將一堆.xml文件導入Access表。 我創建了一個.xslt文件,當我在Access中手動運行導入時,該文件可以正常工作。 但是,當我嘗試使用VBA代碼(從另一篇文章中提取的代碼)轉換.xml文件時,生成的temp.xml文件完全為空。 我想念什么?

Public Sub TransformAndImportMultipleXMLs()
   Dim strFile As String, strPath As String

   Dim xmlDoc As New MSXML2.DOMDocument60
   Dim xslDoc As New MSXML2.DOMDocument60
   Dim newDoc As New MSXML2.DOMDocument60

   strPath = "y:\"
   strFile = Dir(strPath & "*.xml")

   xslDoc.async = False
   xslDoc.validateOnParse = False
   xslDoc.resolveExternals = False

   xslDoc.Load "C:\JSTAdb\LinkIncidentID.xslt"

   While strFile <> ""
      ' REINITIALIZE DOM OBJECTS
      Set xmlDoc = New MSXML2.DOMDocument60
      Set newDoc = New MSXML2.DOMDocument60

      ' LOAD XML SOURCE
      xmlDoc.Load strPath & strFile

      ' TRANSFORM SOURCE
      xmlDoc.transformNodeToObject xslDoc, newDoc
      newDoc.Save "C:\JSTAdb\temp.xml"

      ' APPEND TO TABLES
       Application.ImportXML "C:\JSTAdb\temp.xml", acAppendData
       strFile = Dir()
   Wend

   'RELEASE DOM OBJECTS
   Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
End Sub

我想到了。 .xml文件來自InfoPath表單,其中包含許多大型照片附件。 我沒有等待足夠長的時間來轉換結果。 我只需要一點耐心。 現在工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM