How to convert xlsm files to xlsx in folder

Dodettesky

New Member
Joined
Dec 17, 2015
Messages
4
Hello,

I had no luck finding a post specifically on converting all xlsm files in one folder to xlsx using VBA. Can anyone post a link to an old post?

Thanks!

Dodettesky
 
H
Goal: 'To modify the code to extract input file path from one cell and the output file path from a different cell'

Assuming the INPUT PATH value is in A1 in this format: "C:\Users\Username\Documents\Myfolder1\"
where Myfolder1 is where the files reside that you want to convert to xlsx,

INPath = cells(1,"A")

and Assuming the OUTPUT PATH value is in B2 in this format: "C:\Users\Username\Documents\Myfolder2\"

OUTPath = cells(2,"B")

NOTE: The INPUT and OUTPUT paths must both end with a backwards slash, "\".

Code:
Sub RenameXLSMtoXLSX()
    'Makes a copy in xlsx format (smaller file size) then deletes the xlsm file if you want to...see below
    Dim Files As String, LRow As Integer
    Dim INPath, OUTPath As String

    INPath = Cells(1, "A")        'cell A1 value similar to: C:\Users\Username\Documents\Myfolder1\
    Files = Dir(INPath & "*.xlsm")
    OUTPath = Cells(2, "B")    'cell B1 value similar to: C:\Users\Username\Documents\Myfolder2\
    Application.ScreenUpdating = False

    Do While Files <> ""
        Application.DisplayAlerts = False
        Workbooks.Open Filename:=INPath & Files
        ActiveWorkbook.SaveAs Filename:=OUTPath & Left(Files, InStrRev(Files, ".")) & "xlsx", FileFormat:=xlOpenXMLWorkbook
        SetAttr INPath & Files, vbNormal
        ActiveWorkbook.Close SaveChanges:=False
        'Kill INPath & Files           'Uncomment this line if you want to delete the xlsm files
    Files = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
Let me know how you make out.
Perpa
Hi Perpa...
I need one more suggestion...
I need to add prefix "PRT_MX" to all the converted .xlsx files... How do I do that..!?
 
Upvote 0
H
@ amaresh achar.
Just to help me understand the advantage. Could you tell us how much you saved with how many different workbooks.

Hi jolivanes,

I have tried about 25 files which gets converted about in 12 to 15 seconds...

I am moving towards a bigger Target about 100 to 600 files...
 
Upvote 0
"Hi Perpa...
I need one more suggestion...
I need to add prefix "PRT_MX" to all the converted .xlsx files... How do I do that..!?"

amaresh achar,
Try this...
Change this line of code:
Code:
ActiveWorkbook.SaveAs Filename:=OUTPath & Left(Files, InStrRev(Files, ".")) & "xlsx", FileFormat:=xlOpenXMLWorkbook
To this:
Code:
ActiveWorkbook.SaveAs Filename:=OUTPath & "PRT_MX" & Left(Files, InStrRev(Files, ".")) & "xlsx", FileFormat:=xlOpenXMLWorkbook

Perpa
 
Upvote 0

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