Page 1 of 1

Export xml ตามจำนวนที่กำหนด

Posted: Tue Dec 17, 2013 6:35 pm
by mr.zatan
คือผมอยากจะเพิ่ม Code ให้ Export XML ออกมาไฟล์ล่ะ 100 แถว เช่น มีทั้งหมด 200 แถว Export ออกมาก็จะได้ 2 ไฟล์

รบกวนดูให้หน่อยครับ :D

Code: Select all

Sub Button1_Click()

Dim TheText
Dim TheLineText
TheText = "<?xml version=""1.0""?><product>"
For i = 3 To 10000
If Sheet1.Cells(i, 2) <> "" Then
TheLineText = "<p"
For j = 1 To 15
theCell = Sheet1.Cells(i, j)
theCell = Replace(theCell, "<", "<")
theCell = Replace(theCell, """", """)
theCell = Replace(theCell, ">", ">")
theCell = Replace(theCell, "&", "&")

TheLineText = TheLineText & " C" & j & "=""" & theCell & """"
Next
TheLineText = TheLineText & "></p>"
TheText = TheText & TheLineText
Else
Exit For
End If

Next
TheText = TheText & "</product>"


TheFilePath = Application.ActiveWorkbook.Path
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(TheFilePath & "\Product.xml", True)
a.WriteLine (TheText)
a.Close

End Sub


Re: Export xml ตามจำนวนที่กำหนด

Posted: Tue Dec 17, 2013 6:57 pm
by snasui
:D เขียน Code สำหรับแยกครั้งละ 100 บรรทัดมาก่อน และแจ้งด้วยว่าติดบรรทัดไหน จะได้ช่วยปรับปรุงต่อไปจากนั้นครับ