ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SaveAs csv (https://www.excelbanter.com/excel-programming/385753-saveas-csv.html)

Gert

SaveAs csv
 
Hi,

I have to save one specific sheet (or a copy of this sheet) as a scv
file but at the same time I want to keep the original workbook a xls
file.
Is it possible to do this with a macro ???

thanks in advance
Gert


Damien McBain[_3_]

SaveAs csv
 
Gert wrote:

Hi,

I have to save one specific sheet (or a copy of this sheet) as a scv
file but at the same time I want to keep the original workbook a xls
file.
Is it possible to do this with a macro ???

thanks in advance
Gert


Sub saveascsv()

Dim SaveName
SaveName = "C:\mycsvfile.csv" 'you can refer to a range.text if you want to
make this dynamic

Worksheets("Sheet1").Copy
Workbooks(Workbooks.Count).Activate
Workbooks(Workbooks.Count).SaveAs SaveName, xlCSV
Workbooks(Workbooks.Count).Close SaveChanges:=False

End Sub

FSt1

SaveAs csv
 
hi,
yes it is. but you left out some critical info. Is the cvs file going to
always have the same name? here are 2 possible ways. change and don't change.

Sub mac1SaveRange()
Sheets("Sheet1").activate ' change this to your sheet name
Cells.Select
Selection.Copy
Workbooks.Add
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
'use this code if the name DOES NOT change
'ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\My Documents\XCEL\deleteme.csv", _
FileFormat:=xlCSV, CreateBackup:=False
'change deleteme to your file name.
'use this code if the name DOES change
'Application.Dialogs(xlDialogSaveAs).Show
end sub

Post back if you have problems. I will be going to work soon and probably
wont be back to news groups until tonight. But I'll check to see.

Regards
FSt1
"Gert" wrote:

Hi,

I have to save one specific sheet (or a copy of this sheet) as a scv
file but at the same time I want to keep the original workbook a xls
file.
Is it possible to do this with a macro ???

thanks in advance
Gert



Dave Peterson

SaveAs csv
 
I'd use the same kind of code as Damian, but use the Activeworkbook:

Sub saveascsv2()

Dim SaveName as String
SaveName = "C:\mycsvfile.csv" 'you can refer to a range.text if you want to
'make this dynamic

Worksheets("Sheet1").Copy
with activeworkbook
.SaveAs SaveName, xlCSV
.Close SaveChanges:=False
end with

End Sub

Gert wrote:

Hi,

I have to save one specific sheet (or a copy of this sheet) as a scv
file but at the same time I want to keep the original workbook a xls
file.
Is it possible to do this with a macro ???

thanks in advance
Gert


--

Dave Peterson

Dave Peterson

SaveAs csv
 
Damien, not Damian.

(Sorry Damien)

Gert wrote:

Hi,

I have to save one specific sheet (or a copy of this sheet) as a scv
file but at the same time I want to keep the original workbook a xls
file.
Is it possible to do this with a macro ???

thanks in advance
Gert


--

Dave Peterson


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

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