使用VBA将大型XML文件插入到另一个文件中

我用VBA来创build一个XML文件,我有另一个4MB的XML文件,我需要添加到此。 有没有办法在Excel中embedded文件,然后使用VBA将其附加到创build的XML文件?

我需要将xml作为excel文件的一部分,所以需要将其附加到程序中,以便使用它的其他人不需要定位附加文件。

如果这是不可能的,有没有办法让用户浏览该文件,然后再附加它

Print #1, "</Folder>" Print #1, "</Document>" Print #1, "</kml>" Close #1 

好的,所以我假设你有两个有效的XML文件,都是打开/closuresXML标签,并且你需要提取第二个文件的子节点(所有的子节点,所以基本上除了打开/closuresXML标签)并追加到第一个文件。

这是一个简单的例子,如果你需要在特定的地方附加个别的子节点,你需要添加逻辑/条件来做你需要的。

closures这两个文件。 打开一个新的工作簿,并创build一个VBA过程,如下所示:

 Sub AppendXMLFiles() 'requires reference to Microsoft XML, v6.0' 'requires reference to Microsoft Scripting Runtime' Dim file1 As New MSXML2.DomDocument Dim file2 As New MSXML2.DomDocument Dim appendNode As MSXML2.IXMLDOMNode Dim fso As New Scripting.FileSystemObject '## Load your xml files in to a DOM document' file1.Load "c:\users\david_zemens\desktop\example xml file.xml" file2.Load "c:\users\david_zemens\desktop\another xml file.xml" '## iterate the childnodes of the second file, appending to the first file' For Each appendNode In file2.DocumentElement.ChildNodes file1.DocumentElement.appendChild appendNode Next '## View the new XML in the immediate window' Debug.Print file1.XML '## Write the combined file to a NEW file' ' note: if the specified filepath already exists, this will overwrite it' fso.CreateTextFile("c:\users\david_zemens\desktop\combined xml file.xml", True, False).Write file1.XML Set file1 = Nothing Set file2 = Nothing Set fso = Nothing End Sub