Option Explicit Sub 读取XML节点() '后期绑定 'Dim xdoc As Object 'Set xdoc = CreateObject("MSXML2.DOMDocument") '前期绑定 Dim xdoc As New DOMDocument60 '声明的同时创建XML对象 Dim b As Boolean, root As IXMLDOMElement b = xdoc.Load(ThisWorkbook.Path & "\BookStore1.xml") If b = True Then Set root = xdoc.DocumentElement '获取根节点 Dim i As Integer, j As Integer '获取列标题 With root.ChildNodes(0) '根节点的子节点 For i = 0 To .ChildNodes.Length - 1 '子节点的子节点个数 Cells(1, i + 1) = .ChildNodes(i).nodeName Next i End With '获取书籍信息 For i = 0 To root.ChildNodes.Length - 1 With root.ChildNodes(i) For j = 0 To .ChildNodes.Length - 1 Cells(i + 2, j + 1).Value = .ChildNodes(j).Text Next j End With Next i Else MsgBox "加载失败,指定文件可能不存在" End If End Sub --------------------- 作者:qq_41777527 来源:CSDN 原文:https://blog.csdn.net/qq_41777527/article/details/80886780 版权声明:本文为博主原创文章,转载请附上博文链接!