I am new to VBA and to use VBA on excel and write a macro to export an xml file per row (see the example in the print screen): Excel Example
The Account should be an XML element and the transactionID should be an XML attribute of Account.
Example of Excel row 1 converted into a XML file: Example XML file
So far I have this following VBA code to convert an Excel row-wise into an xml file:
Sub test2XLStoXML()
sTemplateXML = _
"<?xml version='1.0'?>" + vbNewLine + _
"<Account transactionId='???'>" + vbNewLine + "</Account>"
Debug.Print sTemplateXML
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 7
sFile = "/Users/user/Documents/" & .Cells(lRow, 1).Value & ".xml"
Dim sAccount As String
Dim sTransactionId As String
sAccount = CStr(.Cells(lRow, 2).Value)
sTransactionId = CStr(.Cells(lRow, 3).Value)
doc.LoadXML sTemplateXML
doc.getElementsByTagName("Account")(0).appendChild doc.createTextNode(sAccount)
doc.getElementsByTagName("Account")(0).appendChild doc.create???(sTransactionId)
doc.Save sFile
Next
End With
End Sub
But I don't know how to code that the Attribute "transactionID" will get the dynamic values from the excel.
I am glad for some help.
Thanks in advance.