Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Mr.P.
 
Posts: n/a
Default how to convert multiple XLS files to CSV?

Does anyone knows how to convert about 1000 XLS files to CSV files in one go??
I am using Office XP Pro.
  #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.



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

Oops

This is working for all the files that are in the folder C:\Data
Change to your folder

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


"Ron de Bruin" wrote in message ...
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.





  #4   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default how to convert multiple XLS files to CSV?

If all the XLS files are in the same folder, and the folder
contains only the XLS files to convert, use code like the
following:

Dim FName As String
Dim WB As Workbook

ChDrive "H" '<<< CHANGE
ChDir "H:\Test" '<<< CHANGE

FName = Dir("*.xls")
Do Until FName = ""
Set WB = Workbooks.Open(Filename:=FName)
WB.SaveAs Filename:=Replace(FName, ".xls", ".csv"),
FileFormat:=xlCSV
WB.Close savechanges:=True
FName = Dir()
Loop



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Text files into one worksheet-need help [email protected] Excel Discussion (Misc queries) 2 January 21st 06 05:09 PM
How do I print multiple files from windows explorer? GMed Excel Discussion (Misc queries) 1 October 7th 05 07:55 PM
importing multiple text files into the same worksheet Mike D Excel Discussion (Misc queries) 4 July 15th 05 10:39 AM
how i convert excel files with images to access mike Excel Discussion (Misc queries) 1 March 7th 05 05:51 PM
How do I record a macro which should work on multiple files ? Venkataraman.P.E Excel Discussion (Misc queries) 2 January 16th 05 10:26 AM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"