View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Ron de Bruin
 
Posts: n/a
Default how to convert multiple XLS files to CSV?

You can open them in a loop and save them as CSV
Have all workbooks one sheet ?

Try this one that copy the first sheet and save it as CSV

Sub Copyrange_1()
Dim mybook As Workbook
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String
Dim wb As Workbook
SaveDriveDir = CurDir

MyPath = "C:\Data"
'Add a slash at the end if the user forget
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False

Do While FNames < ""
Set mybook = Workbooks.Open(FNames)

mybook.Sheets(1).Copy
Set wb = ActiveWorkbook
With wb
.SaveAs MyPath & "CSV-" & Left(FNames, Len(FNames) - 4), FileFormat:=xlCSV
.Close False
End With

mybook.Close False
FNames = Dir()
Loop

CleanUp:
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Mr.P." wrote in message ...
Does anyone knows how to convert about 1000 XLS files to CSV files in one go??
I am using Office XP Pro.