Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch convert of .xls to .csv ?

227 views
Skip to first unread message

Larry Garner

unread,
Aug 11, 1999, 3:00:00 AM8/11/99
to
I'm looking for a way to batch convert .xls (Microsoft Excel 97) files to
.csv (comma delimited format).
I need to do this outside the Excel environment or, if the source code is
available, to incorporate the conversion in my C++ application.
Is there a program or such that I can use and/or is the .xls format
documented somewhere so that I could write the conversion myself ?

Thanks,
Larry

Bill Manville

unread,
Aug 11, 1999, 3:00:00 AM8/11/99
to
The workbook file format is complicated.
Can you not do it by controlling Excel by automation and running a macro in
Excel along the following lines:

Sub ProcessXLSFilesInDirectory()
Dim aFiles() As String, iFile As Integer
Dim stFile As String, vFile As Variant
Dim stDirectory As String
Dim stCSV As String
Dim stCSVDir As String

' first build an array of the files and then process them
' this is because you may upset the Dir function if you save a file

stDirectory = "D:\TEMP\" ' name of directory to look in
stCSVDir = "D:\CSV\" ' where to put the CSV files
' use Dir function to find XLS files in Directory
stFile = Dir(stDirectory & "*.XLS")
If stFile = "" Then Exit Sub ' no files to process
Do While stFile <> ""
' add to array of files
iFile = iFile + 1
' add one element to the array
ReDim Preserve aFiles(1 To iFile)
aFiles(iFile) = stFile
stFile = Dir() ' gets next file
Loop

' now process the files
Application.DisplayAlerts = False ' no messages about overwriting
For Each vFile In aFiles
Workbooks.Open stDirectory & vFile
stCSV = Application.Substitute(vFile, ".xls", ".csv")
Workbooks(vFile).SaveAs stCSVDir & stCSV, Fileformat:=xlCSV
Workbooks(vFile).Close saveChanges:=False
Next vFile

End Sub


--
Bill Manville
Microsoft Excel MVP
Oxford, England
Larry Garner <larry...@mindspring.com> wrote in message
news:7osoer$t46$1...@nntp3.atl.mindspring.net...

0 new messages