Save or Export to CSV

K

Ken

Hello, I have a macro that i recorded that is intended to export (save) data
from the active worksheet within a workbook to a CSV file. The problem i'm
having is that the macro is saving the entire workbook to a CSV. My file
name is even changing. Following is the code:
----------------------------------------------------------------
Sub SaveAsCSV()
'
' SaveAsCSV Macro
'

Application.DisplayAlerts = False
ActiveSheet.SaveAs Filename:= _
"Z:\Timesheet\Time Sheet 2009.csv" _
, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True

End Sub
---------------------------------------------------------------
The CSV that is being created is correct and accurate. However, my file
name changes from: Time Sheet 2009.xlsm to: Time Sheet.CSV. My intention is
to only convert the data in the Active Sheet and not the entire workbook.
I'm not sure if this is even possible.

Any ideas what might be wrong and how i can correct it?

Many thanks...
 
J

JLatham

I'm in a bit of a rush this minute, but I'll return later if someone else
hasn't jumped in.

For the moment, try using .SaveCopyAs instead of .SaveAs and that at least
will keep from renaming your workbook.
 
J

Jacob Skaria

Try

Dim strFile As String
strFile = "Z:\Timesheet\Time Sheet 2009.csv"
ActiveSheet.Copy
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=strFile, FileFormat:=xlCSVMSDOS
ActiveWorkbook.Close False
Application.DisplayAlerts = True

If this post helps click Yes
 

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