title: Extract Multiple XML Attributes to Excel
body: <p>I have the below XML file that I want to extract specific XML attributes from then put those attributes into an excel file.</p>
  
  <p>Below is my XML file</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;RECIPE xmlns="x-schema:recipe_schema.xml" Format="1.0" Name="Table1&gt;
  &lt;STEP ChLocation="CH1"/&gt;
  &lt;ENDPOINT/&gt;&lt;ENDP_DEVICE Type=""/&gt;
  &lt;PARAMS_STEP&gt;
  &lt;REGULAR&gt;
  &lt;PARAM Alias="Offset1" Name="Offset_1" Value="0"/&gt;
  &lt;PARAM Alias="Offset2" Name="Offset_2" Value="-3.59"/&gt;
  &lt;PARAM Alias="Offset3" Name="Offset_3" Value="0" /&gt;
  &lt;PARAM Alias="Offset4" Name="Offset_4" Value="5.56"/&gt;
  &lt;PARAM Alias="Offset5" Name="Offset_5" Value="0"/&gt;
  &lt;PARAM Alias="Offset6" Name="Offset_6" Value="-3.25"/&gt;
  &lt;PARAM Alias="Offset7" Name="Offset_7" Value="4.66"/&gt;
  </code></pre>
  
  <p>My code below finds all of the Node Attributes(0) and (2) - which is great. I am able to debug.print to the immediate window. </p>
  
  <p>The issue arises when I try and export those to excel. I don't have an issue with extracting Attribute(0), because the string name is constant. However, I do not know how to extract Attribute(2), because the value will change on a regular basis so I cannot reference the value directly. </p>
  
  <p>I was trying to research how to store Attribute(2) as a variable then call that variable, but all I could find was information on XSLT variable, and I was not sure of the VBA syntax to get that to work. I have been researching for a few days now, but cannot figure it out. Everything I see online deals with a literal Value.</p>
  
  <p>I would like to export Attribute(0) and with the associated Attribute(2) to an excel table. 
  Column 1 = Attribute(0) = Offsetx
     , and   Column 2 = Attribute(0) = Valuex</p>
  
  <p>What is the best way to extract and export Attribute(2) to excel since I cannot directly call the value?</p>
  
  <p>Thank you for any help in advance - I really appreciate it. </p>
  
  <p>VBA Code below</p>
  
  <pre><code>Sub GetOffsetName_And_Values()
  
  Dim GetOffsets As ThisWorkbook
  Dim objXML As MSXML2.DOMDocument60
  Set objXML = New MSXML2.DOMDocument60
  Dim xmlNodeList As MSXML2.IXMLDOMNodeList
  Dim xmlNode As MSXML2.IXMLDOMNode
  
  
  Dim strXML As String
  Dim x As IXMLDOMNode
  
  objXML.validateOnParse = False
  strXML = "L:\Recipe\File.xml"
  
  objXML.Load (strXML)
  
  Set xmlNodeList = objXML.getElementsByTagName("*")
  On Error Resume Next
  For Each xmlNode In xmlNodeList
      Debug.Print xmlNode.Attributes(0).Text
      Debug.Print xmlNode.Attributes(2).Text
  
  Next xmlNode
  
  If xmlNode.Attributes(0) = "Offset1" Then ThisWorkbook.Sheets("Sheet2").Range("A2") = "Offset1"
  If xmlNode.Attributes(0) = "Offset2" Then ThisWorkbook.Sheets("Sheet2").Range("A3") = "Offset2"
  If xmlNode.Attributes(0) = "Offset3" Then ThisWorkbook.Sheets("Sheet2").Range("A4") = "Offset3"
  If xmlNode.Attributes(0) = "Offset4" Then ThisWorkbook.Sheets("Sheet2").Range("A5") = "Offset4"
  If xmlNode.Attributes(0) = "Offset6" Then ThisWorkbook.Sheets("Sheet2").Range("A6") = "Offset6"
  If xmlNode.Attributes(0) = "Offset7" Then ThisWorkbook.Sheets("Sheet2").Range("A7") = "Offset7"
  
  
  Set objXML = Nothing
  
  End Sub
  </code></pre>