skapunkboy
New Member
- Joined
- Apr 29, 2015
- Messages
- 8
Hi All
I am after some help
I have been asked if I can convert a spreadsheet that will have a variable number of rows into single XML files for ordering
here is a basic example of my data
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Brand[/TD]
[TD]Quantity[/TD]
[TD]Unique Code[/TD]
[/TR]
[TR]
[TD]Mr Why[/TD]
[TD]Generic Ale[/TD]
[TD]2[/TD]
[TD]XML00001[/TD]
[/TR]
[TR]
[TD]Mr Who[/TD]
[TD]Generic Lager[/TD]
[TD]4[/TD]
[TD]XML00002[/TD]
[/TR]
</tbody>[/TABLE]
So far I have done a bit of searching but I would really like to understand the code rather than just borrowing from the internet
here is what I have thus far to loop through each row and drop it onto a separate tab followed by creating the XML files
This work at creating the right XML data as I did get it to paste into a spare column to check if what I was doing was correct
It also creates the XML files in the folder I wanted but they are blank
Any help would be really appreciated
I need to be able to vary the rows and columns because the document may change with different lines introduced for ordering
thank you in advance
I am after some help
I have been asked if I can convert a spreadsheet that will have a variable number of rows into single XML files for ordering
here is a basic example of my data
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Brand[/TD]
[TD]Quantity[/TD]
[TD]Unique Code[/TD]
[/TR]
[TR]
[TD]Mr Why[/TD]
[TD]Generic Ale[/TD]
[TD]2[/TD]
[TD]XML00001[/TD]
[/TR]
[TR]
[TD]Mr Who[/TD]
[TD]Generic Lager[/TD]
[TD]4[/TD]
[TD]XML00002[/TD]
[/TR]
</tbody>[/TABLE]
So far I have done a bit of searching but I would really like to understand the code rather than just borrowing from the internet
here is what I have thus far to loop through each row and drop it onto a separate tab followed by creating the XML files
Sub XLM_Generation()
Sheet1.Activate
For Each DATA_ROW In Sheet1.Range(Cells(2, "A"), Cells(ActiveSheet.UsedRange.Rows.Count, "A"))
DATA_ROW.EntireRow.Copy
Sheet2.Activate
Sheet2.Range("A2").PasteSpecial
Set XML_DOC = CreateObject("MSXML2.DOMDocument")
XML_DOC.async = False
XML_DOC.validateOnParse = False
XML_DOC.resolveExternals = False
Dim XML_DATA As String
XML_DATA = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbNewLine
XML_DATA = XML_DATA & "<RECORD>" & vbNewLine
For Each CELL In Sheet2.Range("A2:D2")
If CELL.Value = "" Then GoTo NO_DATA
XML_DATA = XML_DATA & "<" & CELL.Offset(-1, 0).Value & ">"
XML_DATA = XML_DATA & CELL.Value
XML_DATA = XML_DATA & "</" & CELL.Offset(-1, 0).Value & ">" & vbNewLine
GoTo DATA
NO_DATA:
XML_DATA = XML_DATA & "<" & CELL.Offset(-1, 0).Value & "/>" & vbNewLine
DATA:
Next
XML_DATA = XML_DATA & "</RECORD>"
XML_DOC.LoadXML XML_DATA
XML_DOC.Save "\XML TEST" & Sheet2.Range("D2").Value & ".XML"
Next
End Sub
This work at creating the right XML data as I did get it to paste into a spare column to check if what I was doing was correct
It also creates the XML files in the folder I wanted but they are blank
Any help would be really appreciated
I need to be able to vary the rows and columns because the document may change with different lines introduced for ordering
thank you in advance