Discussion:
Saving as CSV
(too old to reply)
Dan Freeman
2003-09-16 20:57:39 UTC
Permalink
#DEFINE xlCSV 6
objbook.saveas(filename,xlCSV)

You can find this syntax by recording a macro in Excel to do a SaveAs, and
then look at the generated code.

Dan


ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\danf\My Documents\Book1.csv",
FileFormat:=xlCSV
I'm creating a file in Excel and I want to save the file as a type CSV
once
I have the file created. Can someone please tell me the correct syntax to
use to save this file as CSV? I'm using VFP 7.0.
objexcel = CreateObject("Excel.application")
objexcel.visible = .F.
objbook = objexcel.workbooks.add()
* Make sure columns are in text format
objexcel.columns("A:Z").Select
*** Put data in rows/columns
objexcel.displayalerts = .F. && turn off alerts and questions from Excel
objexcel.range("A1").select
objbook.saveas(filename)
objexcel.quit
Release objbook,objexcel
Brenda L. Sterner
2003-09-17 12:19:11 UTC
Permalink
Thanks so much for the assistance.
I did record the macro but didn't find the code to be very obvious.

Thanks again!
Post by Dan Freeman
#DEFINE xlCSV 6
objbook.saveas(filename,xlCSV)
You can find this syntax by recording a macro in Excel to do a SaveAs, and
then look at the generated code.
Dan
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\danf\My Documents\Book1.csv",
FileFormat:=xlCSV
I'm creating a file in Excel and I want to save the file as a type CSV
once
I have the file created. Can someone please tell me the correct syntax to
use to save this file as CSV? I'm using VFP 7.0.
objexcel = CreateObject("Excel.application")
objexcel.visible = .F.
objbook = objexcel.workbooks.add()
* Make sure columns are in text format
objexcel.columns("A:Z").Select
*** Put data in rows/columns
objexcel.displayalerts = .F. && turn off alerts and questions from Excel
objexcel.range("A1").select
objbook.saveas(filename)
objexcel.quit
Release objbook,objexcel
Andrei Hulog
2003-09-17 10:50:27 UTC
Permalink
If the new CSV file is to be populated from a data source, you could also
use the COPY TO command:
COPY TO <lcFilename> TYPE CSV
oWorkbook = GETOBJECT(<lcFilename>, Excel.Application)

You could still do this even if you're creating a new empty file by using a
dummy cursor / table with no records.

However, the field names are also copied as the first row of the file, so
you would have to delete the first row in Excel.

Loading...