Guest User

Untitled

a guest
Dec 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. Sub MakeXML(iCaptionRow As Integer, iDataStartRow As Integer, sOutputFileName As String)
  2. Dim Q As String
  3. Dim NodeName As String
  4. Dim AtributName As String
  5.  
  6. Application.ScreenUpdating = False
  7.  
  8. Q = Chr$(34)
  9.  
  10. Dim sXML As String
  11.  
  12. sXML = "<?xml version=" & Q & "1.0" & Q & " encoding=" & Q & "UTF-8" & Q & "?>"
  13. sXML = sXML & "<root>"
  14.  
  15. NodeName = "node"
  16. AtributName = "test"
  17.  
  18. ''--determine count of columns
  19. Dim iColCount As Integer
  20. iColCount = 1
  21. While Trim$(Cells(iCaptionRow, iColCount)) > ""
  22. iColCount = iColCount + 1
  23. Wend
  24.  
  25. Dim iRow As Integer
  26. iRow = iDataStartRow
  27.  
  28. While Cells(iRow, 1) > ""
  29. sXML = sXML & "<" & NodeName & " type=" & Q & AtributName & Q & " id=" & Q & iRow & Q & ">"
  30.  
  31. For icol = 1 To iColCount - 1
  32. sXML = sXML & "<" & Trim$(Cells(iCaptionRow, icol)) & ">"
  33. sXML = sXML & Trim$(Cells(iRow, icol))
  34. sXML = sXML & "</" & Trim$(Cells(iCaptionRow, icol)) & ">"
  35. Next
  36.  
  37. sXML = sXML & "</" & NodeName & ">"
  38. iRow = iRow + 1
  39. Wend
  40. sXML = sXML & "</root>"
  41.  
  42. Dim nDestFile As Integer, sText As String
  43.  
  44. ''Close any open text files
  45. Close
  46.  
  47. ''Get the number of the next free text file
  48. nDestFile = FreeFile
  49.  
  50. ''Write the entire file to sText
  51. Open sOutputFileName For Output As #nDestFile
  52. Print #nDestFile, sXML
  53. Close
  54.  
  55. Application.ScreenUpdating = True
  56.  
  57.  
  58. End Sub
  59.  
  60. Sub ExcelToXml()
  61. Dim FileName As String
  62. FileName = InputBox("Dateinamen eingeben:")
  63. Call MakeXML(1, 2, ActiveWorkbook.Path & "" & FileName & ".xml")
  64. End Sub
  65.  
  66. Sub MakeXML(iCaptionRow As Integer, iDataStartRow As Integer, sOutputFileName As String)
  67. Dim Q As String
  68. Dim NodeName As String
  69. Dim AtributName As String
  70. Dim fso As Object
  71. Set fso = CreateObject("Scripting.FileSystemObject")
  72. Dim oFile As Object
  73.  
  74.  
  75. Set oFile = fso.CreateTextFile(sOutputFileName)
  76.  
  77. Application.ScreenUpdating = False
  78.  
  79. Q = Chr$(34)
  80.  
  81. oFile.Write "<?xml version=" & Q & "1.0" & Q & " encoding=" & Q & "UTF-8" & Q & "?>"
  82. oFile.Write "<root>"
  83.  
  84. NodeName = "node"
  85. AtributName = "test"
  86.  
  87. ''--determine count of columns
  88. Dim iColCount As Integer
  89. iColCount = 1
  90. While Trim$(Cells(iCaptionRow, iColCount)) > ""
  91. iColCount = iColCount + 1
  92. Wend
  93.  
  94. Dim iRow As Integer
  95. iRow = iDataStartRow
  96.  
  97. While Cells(iRow, 1) > ""
  98. oFile.Write "<" & NodeName & " type=" & Q & AtributName & Q & " id=" & Q & iRow & Q & ">"
  99.  
  100. For icol = 1 To iColCount - 1
  101. oFile.Write "<" & Trim$(Cells(iCaptionRow, icol)) & ">"
  102. oFile.Write Trim$(Cells(iRow, icol))
  103. oFile.Write "</" & Trim$(Cells(iCaptionRow, icol)) & ">"
  104. Next
  105.  
  106. oFile.Write "</" & NodeName & ">"
  107. iRow = iRow + 1
  108. Wend
  109. oFile.Write "</root>"
  110.  
  111.  
  112. oFile.Close
  113.  
  114. Application.ScreenUpdating = True
  115.  
  116.  
  117. End Sub
Add Comment
Please, Sign In to add comment