saving and converting files from xlsm

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
389
I have about 20 files within my directory, c:/payroll with all of them with a .xlsm extension (they already have macros in the files).

Can a script be created to file save as (or create a copy) but in a different directory, say, c:test/, with a the file extension as .xls. So, have 20 payroll files as .xls, but still keeping the original files as .xlsm.

The reason why is, we cannot import .xlsm spreadsheets in our payroll program.

I am using Excel 2010.

Many thanks for your assistance.

Jay
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I have about 20 files within my directory, c:/payroll with all of them with a .xlsm extension (they already have macros in the files).

Can a script be created to file save as (or create a copy) but in a different directory, say, c:test/, with a the file extension as .xls. So, have 20 payroll files as .xls, but still keeping the original files as .xlsm.

The reason why is, we cannot import .xlsm spreadsheets in our payroll program.

I am using Excel 2010.

Many thanks for your assistance.

Jay


Just record a macro while you save the first file from .xlsm to .xls...then you can use that as your starting point for moving forward. :wink:
 
Upvote 0
You can also search on-line for file converters. Or, you can try the following...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] test()

    [color=darkblue]Dim[/color] strSourcePath [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] strDestPath [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] strFile [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] wkb [color=darkblue]As[/color] Workbook
    [color=darkblue]Dim[/color] Cnt [color=darkblue]As[/color] [color=darkblue]Long[/color]
    
    Application.ScreenUpdating = [color=darkblue]False[/color]
    
    strSourcePath = "C:\Payroll\"
    
    [color=darkblue]If[/color] Right(strSourcePath, 1) <> "\" [color=darkblue]Then[/color] strSourcePath = strSourcePath & "\"
    
    strDestPath = "C:\Test\"
    
    [color=darkblue]If[/color] Right(strDestPath, 1) <> "\" [color=darkblue]Then[/color] strDestPath = strDestPath & "\"
    
    strFile = Dir(strSourcePath & "*.xlsm")
    
    [color=darkblue]Do[/color] [color=darkblue]While[/color] Len(strFile) > 0
        Cnt = Cnt + 1
        [color=darkblue]Set[/color] wkb = Workbooks.Open(strSourcePath & strFile)
        strFile = Left(strFile, InStr(1, strFile, ".xlsm", vbTextCompare) - 1)
        wkb.SaveAs Filename:=strDestPath & strFile & ".xls", FileFormat:=-4143
        wkb.Close savechanges:=[color=darkblue]False[/color]
        strFile = Dir
    [color=darkblue]Loop[/color]
    
    Application.ScreenUpdating = [color=darkblue]True[/color]
    
    [color=darkblue]If[/color] Cnt > 0 [color=darkblue]Then[/color]
        MsgBox "Completed...", vbInformation
    [color=darkblue]Else[/color]
        MsgBox "No files were found...", vbInformation
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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