Saving a sheet in a workbook as .csv but not changing workbook name

G

gloryofbach

Hi everyone,

Thanks for your help on my previous question, it has led me to another
problem:

I have a workbook called work.xls with three sheets, one of which is
called data.

I want to save a copy of data sheet as a csv file called data.csv. This
is easily done using the below code. My problem is I do not want the
name of the current sheet to change when I have done this. In other
words I don't want to save the current workbook as data.csv, but just
the sheet "data". The workbook should remain as work.xls.

This is the code that doesnt work properly:

Sheets("Data").Select
Range("A1").Select

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\Alex\Desktop\data.csv", FileFormat:=
_
xlCSV, CreateBackup:=False
 
K

Kaak

Sheets("Data").Select
Sheets("Data").Copy


ActiveWorkbook.SaveAs Filename:= _
"C:\Data.csv", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,
_
CreateBackup:=False

ActiveWindow.Close
 
G

gloryofbach

Hello Kaak,

Thank you very much for your considered reply - funny enough your
method is the exact same way I am doing it. My issue is that I am
saving the data.csv every 20 seconds for 8 hours a day (the process
runs on a timer to ensure data.csv is always up to date). In this sense
the method seems rather inelegant, as you are having to create a new
workbook each time etc and the temporary workbook number is Book1
etc... by the end of the day it will be book1500 etc...

This isnt a big deal but I am surprised you cannot use savecopyas
function to save a sheet as a csv file!

Is my understanding correct?

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top