Open all Excel files in folder and save as .xls

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,368
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a folder with multiple .xlsm files which I need to programmatically save as .xls file.

Anybody have a vba script to do this?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Here is some code that shows you how to loop through all the files in a specific folder with a specific extension:
https://www.mrexcel.com/forum/excel...sv-files-folder-excel-2011-a.html#post2941307

As far as opening the file, saving it as an "xls" file, and closing the file, you should be able to get the code you need for that by using the Macro Recorder and record yourself doing that step manually.
Then it is just a matter of embedding that code within the loop of the other code.

Give it a try and see how far you get, and if you run into trouble, post the code you have come up with here.
 
Upvote 0
I have a folder with multiple .xlsm files which I need to programmatically save as .xls file.

Anybody have a vba script to do this?

Not fully tested but see if following does what you want:

Rich (BB code):
Sub ChangeFileFormat()
    Dim Folder As String, FileName As String
    Dim wb As Workbook
    
    Folder = "C:\MyFolder\"
    
    FileName = Dir(Folder & "*.xlsm", vbNormal)
    
    On Error GoTo exitsub
    With Application
        .EnableEvents = False: .ScreenUpdating = False
    End With
    Do While FileName <> ""
        
        Set wb = Workbooks.Open(Folder & FileName)
        FileName = Replace(FileName, ".xlsm", ".xls")
        If FileName <> ThisWorkbook.Name Then
            wb.SaveAs FileName:=Folder & FileName, FileFormat:= _
            xlExcel8, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
        End If
        
        wb.Close False
        
        FileName = Dir
        Set wb = Nothing
    Loop
exitsub:
    With Application
        .EnableEvents = True: .ScreenUpdating = True
    End With
    If Err > 0 Then MsgBox (Error(Err)), 48, "error"
End Sub

Change folder path / name shown in RED as required.

Dave
 
Upvote 0
Thanks Joe and Dave. I used a little bit of both and fumbled around until it worked out. Thanks again for your time.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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