I need to convert a spreadsheet to a basic XML Format. The spreadsheet looks like this:
I would like each row from the spreadsheet to look like this on the XML:
<item>
<title>Directory Name</title>
<address>Address, City, State</address>
<phone>Phone</phone>
<cell>Cell Phone</cell>
</item>
Any suggestions?
UPDATE: Per a few things I read, and per @Sancho.s suggested code I have used the following Macro:
Sub xls2xml()
Dim rng1 As Range, rng2 As Range, cl As Range
Set rng1 = Range("A2")
Set rng1 = Range(rng1, rng1.End(xlDown))
For Each cl In rng1
Call dump_xml_line(cl)
Next cl
End Sub
Sub dump_xml_line(cl As Range)
Dim n As Integer
n = FreeFile()
Open "C:\Users\Me\test.txt" For Output As #n
Print #n, "<item>"
Print #n, " <title>" & cl.Text & "</title>"
Print #n, " <address>" & cl.Offset(0, 2).Text & "</address>"
Print #n, " <phone>" & cl.Offset(0, 1).Text & "</phone>"
Print #n, " <cell>" & cl.Offset(0, 3).Text & "</cell>"
Print #n, "</item>"
Close #n
End Sub
I had to use Print instead of Debug.Print because the Immediate Window isn't allowed to show more than 200 lines, and that is much much less than what the output of all this would be. Using this code, it creates the test.txt file, but only puts the very last row into the file, instead of all of them. What is wrong with it?