Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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
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
Need sample for reading value from and writing value to cell E53 from outside Excel Tony Bansten Excel Discussion (Misc queries) 1 June 17th 08 07:03 AM
Writing Fast VBA UDFs - London july19/20 Charles Williams Excel Discussion (Misc queries) 2 May 2nd 06 10:43 PM
Writing Fast VBA UDFs - London july19/20 Charles Williams Excel Worksheet Functions 2 May 2nd 06 10:43 PM
convert 400 word files to excel files fast? CPower[_13_] Excel Programming 1 June 21st 04 10:29 AM
Reading and writing from/into several worksheets Chris Excel Programming 3 December 4th 03 08:24 PM


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

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

About Us

"It's about Microsoft Excel"