Where's the Coding Error? XML files to be saved as .xlsx (batch)

dguenther

Board Regular
Joined
Jun 15, 2011
Messages
75
Hi,

Excel 2007 on Windows 7.

I have a couple thousand .xml files.
A.xml,. B.xml, C.xml etc etc

I simply need them to be .xlsx files.

It's as simple as

(1) Open the file
(2)Convert to .xlsx (manually clicking the Convert button under the Save button on the Office button ribbon)
(3) Close

Then I end up with
A.xlsx, B.xlsx, C.xlsx

I would like to have that automated.

I searched threads and tried to pull answers from two other questions to try and solve the problem programatically, but it fails somewhere.

Here are the chunks I am trying out.

Code:
Sub XMLXLS()
'
' XMLXLS Macro

    ActiveWorkbook.SaveAs Filename:= _
        "C:directoryformyfiles\a.xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close
End Sub


Sub LoopFiles()
Dim MyFileName, MyPath As String
Dim MyBook As Workbook

MyPath = "C:\hereiswheremyfileslive"
MyFileName = Dir(MyPath & "*.xml")

Do Until MyFileName = ""
    Workbooks.Open MyPath & MyFileName
    Set MyBook = ActiveWorkbook

    Application.Run "XMLXLS"

    MyBook.Save
    MyBook.Close
    MyFileName = Dir
Loop
End Sub

Any and all help would be greatly appreciated.

-dguenther
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Knowing what line your code fails on would be a big help.

Other than that, a brief look at your code suggest you may need a few "\" characters as highligehted in red below:

Code:
Sub XMLXLS()
'
' XMLXLS Macro

    ActiveWorkbook.SaveAs Filename:= _
        "C:[B][COLOR=red]\[/COLOR][/B]directoryformyfiles\a.xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close
End Sub


Sub LoopFiles()
Dim MyFileName, MyPath As String
Dim MyBook As Workbook

MyPath = "C:\hereiswheremyfileslive"
MyFileName = Dir(MyPath & "[B][COLOR=red]\[/COLOR][/B]*.xml")

Do Until MyFileName = ""
    Workbooks.Open MyPath & MyFileName
    Set MyBook = ActiveWorkbook

    Application.Run "XMLXLS"

    MyBook.Save
    MyBook.Close
    MyFileName = Dir
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,798
Messages
6,126,970
Members
449,351
Latest member
Sylvine

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