使用VBA动态搜索XML文件中的数据

使用VBA动态搜索XML文件中的数据,xml,vba,excel,Xml,Vba,Excel,我需要在Excel中的VBA中打开一个XML文件。我在XML文件中查找的两个数据字符串位于一个标记下面。这些字符串可以在多个标记下找到,但我还需要连接它们 <Systems> <conveyor ConveyorNumber="132000"> <conveyor>132000</conveyor> <productName>IQ</productName> </conveyor> <

我需要在Excel中的VBA中打开一个XML文件。我在XML文件中查找的两个数据字符串位于一个标记下面。这些字符串可以在多个标记下找到,但我还需要连接它们

<Systems>
  <conveyor ConveyorNumber="132000">
    <conveyor>132000</conveyor>
    <productName>IQ</productName>
  </conveyor>
</Systems>

132000
智商
里面有更多的数据,但我只需要

<conveyor>132000</conveyor>  
132000
&

智商 。有多个

<Systems></Systems>


在文件中,我需要计算文件中的系统数,将所需的两个字符串连接起来,并将它们全部放在Excel工作表的一列中。是否仍要执行此操作?

请尝试下面的代码来解析XML文件

Sub parseXML()

    Dim strPath As String
    strPath = Application.GetOpenFilename

    Dim XDoc As Object
    Set XDoc = CreateObject("MSXML2.DOMDocument")
    XDoc.async = False
    XDoc.validateOnParse = False
    XDoc.Load (strPath)
    Set xObjDetails = XDoc.ChildNodes(0)
    Set xObject = xObjDetails.FirstChild
    For Each xObject In xObjDetails.ChildNodes
        MsgBox "Child nodes count " & xObjDetails.ChildNodes.Length
        For Each xChild In xObject.ChildNodes
            MsgBox xChild.BaseName & " " & xChild.Text
        Next xChild
    Next xObject

End Sub

有没有办法通过选择一个你想要的文件来做到这一点?有没有办法为URL做到这一点?
Sub parseXML()

    Dim strPath As String
    strPath = Application.GetOpenFilename

    Dim XDoc As Object
    Set XDoc = CreateObject("MSXML2.DOMDocument")
    XDoc.async = False
    XDoc.validateOnParse = False
    XDoc.Load (strPath)
    Set xObjDetails = XDoc.ChildNodes(0)
    Set xObject = xObjDetails.FirstChild
    For Each xObject In xObjDetails.ChildNodes
        MsgBox "Child nodes count " & xObjDetails.ChildNodes.Length
        For Each xChild In xObject.ChildNodes
            MsgBox xChild.BaseName & " " & xChild.Text
        Next xChild
    Next xObject

End Sub