Excel VBA 导入 xml 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22666220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:30:10  来源:igfitidea点击:

Excel VBA import xml file

xmlexcelvba

提问by Regenbui

I've used google but i can't seem to find a simple answer to the following question:

我使用过谷歌,但似乎无法找到以下问题的简单答案:

How do I import a XML file into an Excel worksheet using VBA. So for example, i have a file named test.xml in the folder c:\test. I want excel to copy the data of test.xml to the second sheet using VBA

如何使用 VBA 将 XML 文件导入 Excel 工作表。例如,我在文件夹 c:\test 中有一个名为 test.xml 的文件。我希望excel使用VBA将test.xml的数据复制到第二张表

回答by Tim Williams

On the Data tab >> Get External Data >> From other sources >> From XML data import

在数据选项卡上 >> 获取外部数据 >> 从其他来源 >> 从 XML 数据导入

Recording a macro while doing this gave me:

在执行此操作时录制宏给了我:

ActiveWorkbook.XmlImport URL:= "C:\Stuff\test.xml", ImportMap:=Nothing, _
                         Overwrite:=True, Destination:=Range("$A")

Start with that and see if it works for your file. If you run into problems you'll need to post a sample of the actual XML.

从那开始,看看它是否适用于您的文件。如果遇到问题,则需要发布实际 XML 的示例。