Convert multiple XML files in CSV automatically,headers problem with 1 entry xml file

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)
sWxbnS2
sWxbnS2
right.png
[/URL][/IMG]


wrong one
wrong.png
[/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
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top