.xml to .xlsx Code need explained

mayoung

Active Member
Joined
Mar 26, 2014
Messages
259
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I found this code online to convert .xml to .xlsx. Can someone please explain what I need to do to make this work for for me?
Here is what I am trying to convert:

From: C:\user\myoung\downloads\Dataminer.xml

To: C:\user\myoung\downloads\Dataminer.xlsx

Is this code saying to use two folders named xml Folder and convFolder
Where would these folders go?

VBA Code:
Dim objFolder As Object
Dim objFile As Object

xmlFolder = "C:\Users\John\Documents\xml\"
convFolder = "C:\Users\John\Documents\xls\"


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 & "_conv.xlsx"

        Set ConvertThis = Workbooks.Open(objFolder & "\" & objFile.Name)
        ConvertThis.SaveAs Filename:=NewFileName, FileFormat:= _
        xlOpenXMLWorkbook
        ConvertThis.Close
    End If
Next objFile
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I found this code online to convert .xml to .xlsx. Can someone please explain what I need to do to make this work for for me?
Here is what I am trying to convert:

From: C:\user\myoung\downloads\Dataminer.xml

To: C:\user\myoung\downloads\Dataminer.xlsx

Is this code saying to use two folders named xml Folder and convFolder
Where would these folders go?

VBA Code:
Dim objFolder As Object
Dim objFile As Object

xmlFolder = "C:\Users\John\Documents\xml\"
convFolder = "C:\Users\John\Documents\xls\"


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 & "_conv.xlsx"

        Set ConvertThis = Workbooks.Open(objFolder & "\" & objFile.Name)
        ConvertThis.SaveAs Filename:=NewFileName, FileFormat:= _
        xlOpenXMLWorkbook
        ConvertThis.Close
    End If
Next objFile
I figured this code out it works perfect
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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