Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Save one sheet as .csv with macro

I have an Excel file with more than one worksheet. With the Excel file open,
I want to save one of the sheets as a csv file (but name it with a .txt
extension) and leave the original file open (still as an Excel file) to
continue working with it. I have tried using the SaveAs function and I end
up with both the sheet and the original file with a .txt extension--not what
I want. I have also figured out how to create both files IF I close both
files--also not what I want.

I have searched online and have not come up with any help for this scenario.
I would really appreciate advice from someone who can get this working.

Thank you,
Judy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Save one sheet as .csv with macro

One arduous solution is to write VBA code that opens a text file, reads the
sheet cell by cell and writes them to the file and closes the file.

A simpler solution is to use the Jet 4.0 provider to read the sheet in its
entirety into an ADO recordset object and then to write this object , using
its GetString() method to a TXT file. This method allows full control: you
can write a subset of any sheet to a txt file also.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default Save one sheet as .csv with macro

Judy Ward wrote:
I have an Excel file with more than one worksheet. With the Excel
file open, I want to save one of the sheets as a csv file (but name
it with a .txt extension) and leave the original file open (still as
an Excel file) to continue working with it. I have tried using the
SaveAs function and I end up with both the sheet and the original
file with a .txt extension--not what I want. I have also figured out
how to create both files IF I close both files--also not what I want.

I have searched online and have not come up with any help for this
scenario. I would really appreciate advice from someone who can get
this working.

Thank you,
Judy


Get a copy of the free ASAP Utilities addin. It allows one to expost a
selection to CSV


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Save one sheet as .csv with macro

You can copy that sheet to a new workbook and save it from there.

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim newWks As Worksheet

set wks = worksheets("whateveroneyouwanthere")

wks.Copy 'to a new workbook
Set newWks = ActiveSheet

With newWks
Application.DisplayAlerts = False
.Parent.SaveAs Filename:="C:\TEMP\" & .Name & ".txt", _
FileFormat:=xlCSV
Application.DisplayAlerts = True
.Parent.Close savechanges:=False
End With

End Sub

Judy Ward wrote:

I have an Excel file with more than one worksheet. With the Excel file open,
I want to save one of the sheets as a csv file (but name it with a .txt
extension) and leave the original file open (still as an Excel file) to
continue working with it. I have tried using the SaveAs function and I end
up with both the sheet and the original file with a .txt extension--not what
I want. I have also figured out how to create both files IF I close both
files--also not what I want.

I have searched online and have not come up with any help for this scenario.
I would really appreciate advice from someone who can get this working.

Thank you,
Judy


--

Dave Peterson
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
Macro to Save just one sheet to new workbook. Guy[_2_] Excel Worksheet Functions 2 January 27th 09 09:32 PM
how do I get a macro to save a sheet and set the file name? MadasMax Excel Discussion (Misc queries) 1 September 16th 07 12:04 PM
How can I save my sheet in macro FSt1 Excel Discussion (Misc queries) 2 February 10th 07 08:54 AM
How do I save each sheet as a separate .xls file by using macro? Min Excel Programming 5 February 17th 05 10:47 PM
is it possible to change this macro to save each sheet seperately? Martyn Excel Programming 4 May 15th 04 07:04 PM


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

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

About Us

"It's about Microsoft Excel"