Batch Convert CSV to XLS

G

Guest

Hi Everyone!

Can anyone show me the code for a macro that will format a folder full of
CSV files to XLS files automatically.

Thanks
Dave
 
B

Bernie Deitrick

Dave,

Try the macro below. Just change the path to your folder....

HTH,
Bernie
MS Excel MVP


Sub TransformCSVToXls()
Application.DisplayAlerts = False
myFile = ActiveWorkbook.Name
myPath = "C:\Documents and Settings\DEITBE\My Documents\Excel\Delete These\"
WorkFile = Dir(myPath & "*.CSV")

Do While WorkFile <> ""
Application.StatusBar = "Now working on " & WorkFile
Workbooks.Open FileName:=myPath & WorkFile
MsgBox ActiveWorkbook.Name
ActiveWorkbook.SaveAs FileName:=myPath & _
Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4), FileFormat:=xlNormal
ActiveWorkbook.Close
Windows(myFile).Activate
WorkFile = Dir()
Loop

Application.StatusBar = False

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top