title: Run-time error '13' VBA Macro Excel
body: <p>I created this macro and I get a Run-time error '13' at the line</p>
  
  <pre><code>Set objDomAttribute = objDomElement3.Attributes.setNamedItem(objDomDoc.createAttribute("Name4"))
  </code></pre>
  
  <p>My Excel file has 2727 rows. I tested it for fewer rows and it works perfectly, but for 2727 it doesn't work. What should I do for solving that?</p>
  
  <pre><code>Option Explicit
  Public Sub MakeXMLWithDom() 
  
  Dim Q As String 
  Q = Chr$(34) 
  
  Dim objDomDoc As New MSXML2.DOMDocument60 
  
  objDomDoc.LoadXML ("&lt;?xml version=" &amp; Q &amp; "1.0" &amp; Q &amp; "encoding=" &amp; Q &amp; "utf-8" &amp; Q &amp; "?&gt;") 
  
  Dim objDomElement As MSXML2.IXMLDOMElement 
  Dim objDomAttribute As MSXML2.IXMLDOMAttribute 
  Dim nodeSet As MSXML2.IXMLDOMNodeList 
  
  Set objDomElement = objDomDoc.createElement("Containers") 
  Set objDomElement = objDomDoc.appendChild(objDomElement) 
  
   'finding the amount of rows in the excel
  Dim numofrows As Long 
  numofrows = Worksheets("EXAMPLE").Range("E1").Offset(Worksheets("EXAMPLE").Rows.Count - 1, 0).End(xlUp).Row 
  
  Dim iRow As Integer 
  
  Dim Value11 As Variant 
  Dim Value12 As Variant 
  Dim Value13 As Variant 
  
  Dim objDomElement1 As Variant
  Dim objDomElement2 As Variant
  Dim objDomElement3 As Variant
  
  For iRow = 10 To (numofrows + 1) 
  
      If Worksheets("EXAMPLE").Cells(iRow - 1, 5) = Worksheets("EXAMPLE").Cells(iRow, 5) Then 
          Value11 = Worksheets("EXAMPLE").Cells(iRow - 1, 11).Value &amp; ", " &amp; Worksheets("EXAMPLE").Cells(iRow, 11).Value 
          Value12 = Worksheets("EXAMPLE").Cells(iRow - 1, 12).Value &amp; ", " &amp; Worksheets("EXAMPLE").Cells(iRow, 12).Value 
          Value13 = Worksheets("EXAMPLE").Cells(iRow - 1, 13).Value &amp; ", " &amp; Worksheets("EXAMPLE").Cells(iRow, 13).Value 
      Else 
          Value11 = Worksheets("EXAMPLE").Cells(iRow, 11).Value 
          Value12 = Worksheets("EXAMPLE").Cells(iRow, 12).Value 
          Value13 = Worksheets("EXAMPLE").Cells(iRow, 13).Value 
      End If 
  
      If Worksheets("EXAMPLE").Cells(iRow, 5) &lt;&gt; Worksheets("EXAMPLE").Cells(iRow + 1, 5) And Worksheets("EXAMPLE").Cells(iRow, 3) &lt;&gt; "" And Worksheets("EXAMPLE").Cells(iRow, 5) &lt;&gt; "" Then 
  
          Set objDomElement1 = objDomElement.appendChild(objDomDoc.createElement("Data")) 
          Set objDomAttribute = objDomElement1.Attributes.setNamedItem(objDomDoc.createAttribute("Relevant")) 
          objDomElement1.Attributes.getNamedItem("Relevant").Text = "True" 
  
          Set objDomElement2 = objDomElement1.appendChild(objDomDoc.createElement("Info")) 
  
          Set objDomElement3 = objDomElement2.appendChild(objDomDoc.createElement("Part")) 
          Set objDomAttribute = objDomElement3.Attributes.setNamedItem(objDomDoc.createAttribute("Name1")) 
          Set objDomAttribute = objDomElement3.Attributes.setNamedItem(objDomDoc.createAttribute("Name2")) 
          Set objDomAttribute = objDomElement3.Attributes.setNamedItem(objDomDoc.createAttribute("Name3")) 
          Set objDomAttribute = objDomElement3.Attributes.setNamedItem(objDomDoc.createAttribute("Name4")) 
  
          objDomElement3.Attributes.getNamedItem("Name1").Text = Trim$(Worksheets("EXAMPLE").Cells(iRow, 5).Value) 
          objDomElement3.Attributes.getNamedItem("Name2").Text = Value11 
          objDomElement3.Attributes.getNamedItem("Name3").Text = Value12 
          objDomElement3.Attributes.getNamedItem("Name4").Text = Value13 
  
      End If 
  Next iRow 
  
  objDomDoc.Save ("c:\Example.xml") 
  End Sub
  </code></pre>