ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save one worksheet from a workbook to a new .csv file (https://www.excelbanter.com/excel-programming/377018-save-one-worksheet-workbook-new-csv-file.html)

Chuck M

Save one worksheet from a workbook to a new .csv file
 
Hi,

In code, how can I save one specific worksheet from a workbook with many
worksheets to a new .csv file. I've looked at the SaveAs Method in Help but I
don't see the answer there. Any help would be appreciated.
--
Thanks.
Chuck M.

Ron de Bruin

Save one worksheet from a workbook to a new .csv file
 
Hi Chuck

Try this for the activesheet

Sub ActiveSheet_CSV_File()
Dim wb As Workbook
Dim strdate As String
Dim Fname As String
strdate = Format(Now, "dd-mmm-yy h-mm-ss")
Fname = "C:\Part of " & ThisWorkbook.Name _
& " " & strdate & ".csv"
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs Fname, FileFormat:=xlCSV
.Close False
End With
Application.ScreenUpdating = True
End Sub




--
Regards Ron de Bruin
http://www.rondebruin.nl



"Chuck M" wrote in message ...
Hi,

In code, how can I save one specific worksheet from a workbook with many
worksheets to a new .csv file. I've looked at the SaveAs Method in Help but I
don't see the answer there. Any help would be appreciated.
--
Thanks.
Chuck M.




Chuck M

Save one worksheet from a workbook to a new .csv file
 
Hi Ron,

That works perfectly.

Thanks for the quick response.
--
Thanks.
Chuck M.


"Ron de Bruin" wrote:

Hi Chuck

Try this for the activesheet

Sub ActiveSheet_CSV_File()
Dim wb As Workbook
Dim strdate As String
Dim Fname As String
strdate = Format(Now, "dd-mmm-yy h-mm-ss")
Fname = "C:\Part of " & ThisWorkbook.Name _
& " " & strdate & ".csv"
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs Fname, FileFormat:=xlCSV
.Close False
End With
Application.ScreenUpdating = True
End Sub




--
Regards Ron de Bruin
http://www.rondebruin.nl



"Chuck M" wrote in message ...
Hi,

In code, how can I save one specific worksheet from a workbook with many
worksheets to a new .csv file. I've looked at the SaveAs Method in Help but I
don't see the answer there. Any help would be appreciated.
--
Thanks.
Chuck M.






All times are GMT +1. The time now is 04:06 PM.

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