bglumac
10-18-2016, 04:01 AM
Hi guys, I need help with VBA for button to export .xml table by selection.
I tried to copy and combine some example code but with no luck.
It creates .xml but not for selection or fixed range (never mind) but the data is wrong as I don't know how to code it properly...
The code is:
Private Sub Xml_click()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
myFile = ActiveWorkbook.Path & "\Popis.xml"
Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
End Sub
What I need is a creation of .xml file with two columns of data from selected cells or entire table after clicking the button.
If someone could help, it would be a life saver
Thank you all in advance !!!
I tried to copy and combine some example code but with no luck.
It creates .xml but not for selection or fixed range (never mind) but the data is wrong as I don't know how to code it properly...
The code is:
Private Sub Xml_click()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
myFile = ActiveWorkbook.Path & "\Popis.xml"
Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
End Sub
What I need is a creation of .xml file with two columns of data from selected cells or entire table after clicking the button.
If someone could help, it would be a life saver
Thank you all in advance !!!