Alessio9899
New Member
- Joined
- May 10, 2019
- Messages
- 4
Hello everybody! Like the title i need to do this task. I found this code on web that fits perfectly with my goal:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Public Sub ConvertXmlToXlsx()
Application.DisplayAlerts = False
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
xmlFolder = "C:\Users\xxx\xxx\xxx\xxx"
convFolder = "C:\Users\xxx\xxx\xxx\xxx"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(xmlFolder)
For Each objFile In objFolder.Files
If UCase(Right(objFile.Name, Len(XML))) = UCase(XML) Then
NewFileName = convFolder & objFile.Name & ".xlsx"
Workbooks.OpenXML (objFolder & "" & objFile.Name), LoadOption:=xlXmlLoadImportToList
ActiveWorkbook.SaveAs Filename:=NewFileName
ActiveWorkbook.Close
End If
Next objFile
End Sub</code>
It works without any issues as long as there are at least 2 entries in the XML file but there many xml with just one entry and this code doesn't create the right header attribute for each value:
right case(what i need)
[/URL][/IMG]
wrong one
[/URL]
upload photo
[/IMG]
in this last case there's no header and i need all attributes to import these in my neo4j database.
Is there a way to set that script to automatically recognise every attribute for 1 entry xml file? Thanks to everybody
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Public Sub ConvertXmlToXlsx()
Application.DisplayAlerts = False
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
xmlFolder = "C:\Users\xxx\xxx\xxx\xxx"
convFolder = "C:\Users\xxx\xxx\xxx\xxx"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(xmlFolder)
For Each objFile In objFolder.Files
If UCase(Right(objFile.Name, Len(XML))) = UCase(XML) Then
NewFileName = convFolder & objFile.Name & ".xlsx"
Workbooks.OpenXML (objFolder & "" & objFile.Name), LoadOption:=xlXmlLoadImportToList
ActiveWorkbook.SaveAs Filename:=NewFileName
ActiveWorkbook.Close
End If
Next objFile
End Sub</code>
It works without any issues as long as there are at least 2 entries in the XML file but there many xml with just one entry and this code doesn't create the right header attribute for each value:
right case(what i need)
![right.png](/board/proxy.php?image=http%3A%2F%2F%5BURL%3D%22https%3A%2F%2Fibb.co%2FsWxbnS2%22%5D%5BIMG%5Dhttps%3A%2F%2Fi.ibb.co%2F0s4mTNc%2Fright.png&hash=b04c70c46d2b06b1fc94c1f4fecc6622)
wrong one
![wrong.png](/board/proxy.php?image=http%3A%2F%2F%5BURL%3D%22https%3A%2F%2Fibb.co%2Fdm5W0Zz%22%5D%5BIMG%5Dhttps%3A%2F%2Fi.ibb.co%2F1zmvfcw%2Fwrong.png&hash=c51b43b6b082a03fa2921f6b80bc617a)
upload photo
[/IMG]
in this last case there's no header and i need all attributes to import these in my neo4j database.
Is there a way to set that script to automatically recognise every attribute for 1 entry xml file? Thanks to everybody