Convert .xls to .csv


Posted by Digger on April 04, 2001 8:55 AM

Please can anyone help with the following, i have a folder full of .xls files(400+) which need to be coverted to .csv files how do i do this (renaming the ext'n in explorer doesn't have the required effect)
I dont want to open 1 by 1 ?????????
Is their macro code????



Posted by Barrie Davidson on April 04, 2001 9:09 AM

Try this, I think it'll work for you.

Sub Convert_Macro()
'
'
Dim File_Names As Variant
Dim File_count As Integer
Dim Active_File_Name As String
Dim Counter As Integer
Dim File_Save_Name As Variant


File_Names = Application.GetOpenFilename(, , , , True)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
File_count = UBound(File_Names)
Counter = 1
Do Until Counter > File_count
Active_File_Name = File_Names(Counter)
Workbooks.Open FileName:=Active_File_Name
Active_File_Name = ActiveWorkbook.Name
File_Save_Name = InStr(1, Active_File_Name, ".xls", 1) - 1
File_Save_Name = Mid(Active_File_Name, 1, File_Save_Name) & ".csv"
ActiveWorkbook.SaveAs FileName:=File_Save_Name, FileFormat:= _
xlCSV
ActiveWindow.Close
Counter = Counter + 1
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub