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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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