我有两个xslt文件加载到我的ms access vba中。这个访问数据库将被传递,以便最小化丢失的xslt文件我想知道是否有可能将xsl写入vba?
这是我的vba代码:
Private Sub btnImport_Click()
Dim strFile As String, strPath As String
' REFERENCE MS XML, v6.0
Dim xmlDoc As New MSXML2.DOMDocument60, xslDoc As New MSXML2.DOMDocument60
Dim newDoc As New MSXML2.DOMDocument60
strPath = "C:\Users\1122335\Desktop\iavms\IAVM XML dump on 2017-01-20\"
strFile = Dir(strPath & "*.xml")
' LOAD XSL ONLY ONCE
xslDoc.Load "C:\Users\1122335\Desktop\secondLoad.xsl"
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:\Users\1122335\Desktop\temp.xml"
' APPEND TO TABLES
On Error Resume Next
Application.ImportXML "C:\Users\1122335\Desktop\temp.xml", acAppendData
strFile = Dir()
Wend
' RELEASE DOM OBJECTS
Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
strPath = "C:\Users\1122335\Desktop\iavms\IAVM XML dump on 2017-01-20\"
strFile = Dir(strPath & "*.xml")
' LOAD XSL ONLY ONCE
xslDoc.Load "C:\Users\1122335\Desktop\finally.xsl"
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:\Users\1122335\Desktop\temp.xml"
' APPEND TO TABLES
On Error Resume Next
Application.ImportXML "C:\Users\1122335\Desktop\temp.xml", acAppendData
strFile = Dir()
Wend
' RELEASE DOM OBJECTS
Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
End Sub
答案 0 :(得分:0)
我的答案可能为时已晚,但是要解决此问题,只需将方法“ load”更改为“ loadXML”:
更改自:
xmlDoc.Load strPath & strFile
至:
xslDoc.loadXML strPath & strFile