Maybe this might work as a general concept?
Sub ConvertToXML() ' Declare variables Dim wb As Workbook Dim ws As Worksheet Dim xmlFileName As String Dim lastRow As Long Dim i As Long ' Set the workbook and worksheet Set wb = ThisWorkbook Set ws = wb.Sheets("Sheet1") ' Replace "Sheet1" with your sheet name ' Set the XML file name xmlFileName = "C:\Path\To\Your\File\Output.xml" ' Replace with your desired path ' Open the XML file for output Open xmlFileName For Output As #1 ' Write XML header Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>" ' Get the last row with data lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' Loop through each row and write data to XML For i = 1 To lastRow Print #1, "<Row>" ' Loop through each column in the row For j = 1 To ws.Cells(i, ws.Columns.Count).End(xlToLeft).Column Print #1, " <Column" & j & ">" & ws.Cells(i, j).Value & "</Column" & j & ">" Next j Print #1, "</Row>" Next i ' Close the XML file Close #1 ' Message box to indicate successful conversion MsgBox "Excel sheet successfully converted to XML.", vbInformation End Sub




Reply With Quote
