I built a code that creates a .xml file for each row, for example, the below spreadsheet

The following code works fine except for one case when ResetDate has the same value for more than 1 row.
The VBA code (I'm not an expert)
Sub testXLStoXML()
sTemplateXML = _
"<?xml version='1.0'?>" + vbNewLine + _
"<E>" + vbNewLine + _
" <ResetDate>" + vbNewLine + _
" </ResetDate>" + vbNewLine + _
" <ValueDate>" + vbNewLine + _
" </ValueDate>" + vbNewLine + _
" <MaturityD>" + vbNewLine + _
" </MaturityD>" + vbNewLine + _
" <Rate>" + vbNewLine + _
" </Rate>" + vbNewLine + _
" <Quantity>" + vbNewLine + _
" </Quantity>" + vbNewLine + _
" <ID>" + vbNewLine + _
" </ID>" + vbNewLine + _
"</E>" + vbNewLine
Set doc = CreateObject("MSXML2.DOMDocument")
doc.async = False
doc.validateOnParse = False
doc.resolveExternals = False
With ActiveWorkbook.Worksheets(1)
lLastRow = .UsedRange.Rows.Count
For lRow = 2 To lLastRow
sFile = Format(.Cells(lRow, 1).Value, "DD-MMM-YY")
sBirthdate = Format(.Cells(lRow, 2).Value, "DD-MMM-YY")
sAmount = Format(.Cells(lRow, 3).Value, "DD-MMM-YY")
sRate = .Cells(lRow, 4).Value
sQuantity = .Cells(lRow, 5).Value
sID = .Cells(lRow, 6).Value
doc.LoadXML sTemplateXML
doc.getElementsByTagName("ResetDate")(0).appendChild doc.createTextNode(ResetDate)
doc.getElementsByTagName("ValueDate")(0).appendChild doc.createTextNode(ValueDate)
doc.getElementsByTagName("MaturityD")(0).appendChild doc.createTextNode(MaturityD)
doc.getElementsByTagName("Rate")(0).appendChild doc.createTextNode(sRate)
doc.getElementsByTagName("Quantity")(0).appendChild doc.createTextNode(sQuantity)
doc.getElementsByTagName("ID")(0).appendChild doc.createTextNode(sID)
doc.Save sFile
Next
End With
End Sub
As you can see I get as output just 1 file for the date:
Any suggestions? Thanks in advance


sFile = Format(.Cells(lRow, 1).Value, "DD-MMM-YY"), which references column 1, in which your `ResetDate1 is contained, hence two files will have the same name :0)