I'm new in coding so help is highly appriciated. I'm trying to update an XML code using a table in excel as input. I managed to update a single attribute in the file but I want to make a loop to update multiple variables. I used the tutorial on https://excel-macro.tutorialhorizon.com/vba-excel-update-xml-file/
This code works for one attribute
Function fnUpdateXMLByTags2()
Dim mainWorkBook As Workbook
Set mainWorkBook = ActiveWorkbook
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
XMLFileName = Application.GetOpenFilename(Title:="Please choose XML-file with Load Case definitions", FileFilter:="XML Files *.xml (*.xml),")
oXMLFile.Load (XMLFileName)
Set oAttribute = oXMLFile.SelectSingleNode("/project/container/table/obj[2]/p7/@v")
oAttribute.Text = mainWorkBook.Sheets("Sheet1").Range("G" & i + 2).Value
oXMLFile.Save (XMLFileName)
End Function
Something like this could be it, but I can't get it to work;
Set Attribute_A = oXMLFile.SelectNodes("/project/container/table/obj")
For i = 0 To Attribute_A.Length - 1
Set oAttribute = oXMLFile.SelectSingleNode("/project/container/table/obj[i]/p7/@v")
oAttribute.Text = mainWorkBook.Sheets("Sheet1").Range("G" & i + 2).Value
Next