加载一个带有variables文件名的XML文件,用XSL进行转换

我正在寻找在Excel VBA中运行以下:

Dim xmldoc As Object, xsldoc As Object, newdoc As Object Set xmldoc = CreateObject("MSXML2.DOMDocument") Set xsldoc = CreateObject("MSXML2.DOMDocument") Set newdoc = CreateObject("MSXML2.DOMDocument") ' LOAD XML xmldoc.async = False xmldoc.Load ActiveWorkbook.Path & "\Original.xml" ' LOAD XSL xsldoc.async = False xsldoc.Load ActiveWorkbook.Path & "\XSLT_File.xsl" ' TRANSFORM xmldoc.transformNodeToObject xsldoc, newdoc newdoc.Save ActiveWorkbook.Path & "\Output.xml" 

我在相同的代码中运行这个,但之后,步骤,而原始的XML被导出

 ActiveWorkbook.SaveAsXMLData xmlDirName & fileName & ".xml", objMapToExport 

其中“文件名”是执行保存时的时间戳。

如何重写LOAD XML VBA,以便知道加载刚在代码中创build的XML?

只需将导出的XML文件名作为parameter passing给运行XSLT转换的子例程或函数,前提是两个过程位于相同的工作表或相同的模块之后。

 Public Sub XMLExport() ...rest of code... ActiveWorkbook.SaveAsXMLData xmlDirName & fileName & ".xml", objMapToExport Call XSLTransformation(xmlDirName & fileName & ".xml") End Sub Public Sub XSLTransformation(strfile As String) Dim xmldoc As Object, xsldoc As Object, newdoc As Object Set xmldoc = CreateObject("MSXML2.DOMDocument") Set xsldoc = CreateObject("MSXML2.DOMDocument") Set newdoc = CreateObject("MSXML2.DOMDocument") ' LOAD XML xmldoc.async = False xmldoc.Load strfile ' <------ CHANGE HERE ' LOAD XSL xsldoc.async = False xsldoc.Load ActiveWorkbook.Path & "\XSLT_File.xsl" ' TRANSFORM xmldoc.transformNodeToObject xsldoc, newdoc newdoc.Save ActiveWorkbook.Path & "\Output.xml" End Sub