Writing records to CSV file
Jennifer,
I actually need to use the xlCSV file format as one of the endusers will be
reviewing the file in Excel before its data is uploaded to a mainframe
application.
Ken
"Jennifer" wrote:
On Sep 21, 1:06 pm, Ken Warthen
wrote:
I have an Excel 2003 workbook in which users select a number of products,
enter pricing, margins, etc. When the user is finished I need to create a
csv file with every permutations of their selections and entries. I
originally was writing the records to a worksheet and then when finished I
would export the worksheet to a CSV file. My code worked fine until it was
discovered that frequently the number of records could run into the hundreds
of thousands, exceeding Excel 2003's 65k limit.
I need to rewrite my code to write records directly to an external CSV file.
If anyone has any experience in this area that they could share, I would be
very appreciative.
Ken
You could use the File System Object. You can create a text file and
write the line - repeating the write part however many times is
needed.
Not having seen your code, below is very basic code - some variable
declarations and an example of writing a line to a file. I would
suspect you need to set it up in a loop of some kind, but without
seeing your code I don't know. Hope this helps.
Dim FSO
Dim sFileName
Dim Fil
Dim sLine as String
Dim sCol1 as String
Dim sCol2 as String
Dim sCol3 as String
Dim sCol4 as String
Set FSO = CreateObject("Scripting.FileSystemObject")
sFileName = "C:\File.CSV"
Set Fil = fso.OpenTextFile(sFileName, 2)
sLine = sCol1 & "," sCol2 & "," & sCol3 & "," & sCol4 & vbCrLf
Fil.WriteLine sLine
Fil.Close
Set FSO = Nothing
|