【发布时间】:2017-02-16 18:59:40
【问题描述】:
我有两个 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
【问题讨论】:
-
您想将文件二进制文件作为 base-64 字符串嵌入到 VBA 中吗?为什么不将它们作为
Attachments 嵌入到 Access 表中? -
我是新手。我该怎么做?
-
这就是@ThunderFrame 的建议。调用该表的 vba 代码是什么?
-
XLST 只是文本。您只需要一个备注字段。
-
不用担心我是双向的;)所以代码是
xsldoc [table].[field] where id = 1吗?