ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Fast reading/writing of CSV files (https://www.excelbanter.com/excel-programming/306126-fast-reading-writing-csv-files.html)

Chris Jakeman

Fast reading/writing of CSV files
 
Hi,

As part of a major Excel project, I need to write out a worksheet as a
CSV file and to read it back in.

I've chosen to do this the quick way as the worksheet may have
thousands of rows in it, so I don't want to do file i/o line by line.

I met a few problems along the way which I think I've solved. Anyone
else tried this?

Bye for now,

Chris Jakeman
Peterborough, UK

Dave Peterson[_3_]

Fast reading/writing of CSV files
 
Option Explicit
Sub testme01()
Dim wks As Worksheet
Set wks = Worksheets("sheet1")
wks.Copy 'to a new workbook
With ActiveSheet.Parent
.SaveAs Filename:="whateveryousaveitas.CSV", FileFormat:=xlCSV
.Close savechanges:=False
End With
Workbooks.Open Filename:="whateveryousaveitas.CSV"
End Sub

Chris Jakeman wrote:

Hi,

As part of a major Excel project, I need to write out a worksheet as a
CSV file and to read it back in.

I've chosen to do this the quick way as the worksheet may have
thousands of rows in it, so I don't want to do file i/o line by line.

I met a few problems along the way which I think I've solved. Anyone
else tried this?

Bye for now,

Chris Jakeman
Peterborough, UK


--

Dave Peterson


Chris Jakeman

Fast reading/writing of CSV files
 
On Thu, 05 Aug 2004 21:48:09 -0500, Dave Peterson
wrote:

Option Explicit
Sub testme01()
Dim wks As Worksheet
Set wks = Worksheets("sheet1")
wks.Copy 'to a new workbook
With ActiveSheet.Parent
.SaveAs Filename:="whateveryousaveitas.CSV", FileFormat:=xlCSV
.Close savechanges:=False
End With
Workbooks.Open Filename:="whateveryousaveitas.CSV"
End Sub


Thanks, Dave. That's very neat.

Using .SaveAs from the current workbook creates the CSV file but
renames your workbook - which is pretty undesirable. Copying or moving
to new temporary workbook as you've done avoids the problem.


Bye for now,

Chris Jakeman
Peterborough, UK


Bye for now,

Chris Jakeman
Peterborough, UK


All times are GMT +1. The time now is 10:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com