Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Husker87
 
Posts: n/a
Default How do I copy a worksheet from a workbook as csv file

I have a workbook with several worksheets. I want to record a macro that
will save one tab, "CSV Data" as its own csv file to another location. Any
ideas?
  #2   Report Post  
Ron de Bruin
 
Posts: n/a
Default

Try this one to save the file in C:\

Sub Sheet_CSV_File()
Dim wb As Workbook
Dim strdate As String
Dim Fname As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Fname = "C:\Part of " & ThisWorkbook.Name _
& " " & strdate & ".csv"

Application.ScreenUpdating = False
Sheets("CSV Data").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



"Husker87" wrote in message ...
I have a workbook with several worksheets. I want to record a macro that
will save one tab, "CSV Data" as its own csv file to another location. Any
ideas?



  #3   Report Post  
Gord Dibben
 
Posts: n/a
Default

Husker

In order to record a macro one must go to ToolsMacroRecord New Macro.

And when done the macro usually must be edited somewhat.

Sub Macro2()
Dim w As Worksheet
Set w = Sheets("CSV Data")
Application.DisplayAlerts = False
w.Copy
ActiveWorkbook.SaveAs Filename:="E:\GordStuff\" & w.Name, _
FileFormat:=xlCSV
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub


Gord Dibben Excel MVP

On Thu, 24 Mar 2005 12:55:05 -0800, "Husker87"
wrote:

I have a workbook with several worksheets. I want to record a macro that
will save one tab, "CSV Data" as its own csv file to another location. Any
ideas?


  #4   Report Post  
Husker87
 
Posts: n/a
Default

Short follow up... btw this worked great. I changed the C: to A: so I could
save it to a disk. Here is my follow-up... can I change your code that
names the file to include the content of a cell on the CSV Data sheet? For
example the user has to enter a unique number into a cell "E1" on the CSV
Data worksheet. I would like the name of the CSV file to start with that
number in "E1" then followed by the date like you wrote it. Is that
possible?

"Ron de Bruin" wrote:

Try this one to save the file in C:\

Sub Sheet_CSV_File()
Dim wb As Workbook
Dim strdate As String
Dim Fname As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Fname = "C:\Part of " & ThisWorkbook.Name _
& " " & strdate & ".csv"

Application.ScreenUpdating = False
Sheets("CSV Data").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



"Husker87" wrote in message ...
I have a workbook with several worksheets. I want to record a macro that
will save one tab, "CSV Data" as its own csv file to another location. Any
ideas?




  #5   Report Post  
Ron de Bruin
 
Posts: n/a
Default

Hi

First of all never save to a floppy this way.
Always save to C:\ and copy manual to A


Try this

Sub Sheet_CSV_File_2()
Dim wb As Workbook
Dim strdate As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Application.ScreenUpdating = False
Sheets("CSV Data").Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & wb.Sheets(1).Range("E1") & " " & _
strdate & ".csv", FileFormat:=xlCSV
.Close False
End With
Application.ScreenUpdating = True
End Sub


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



"Husker87" wrote in message ...
Short follow up... btw this worked great. I changed the C: to A: so I could
save it to a disk. Here is my follow-up... can I change your code that
names the file to include the content of a cell on the CSV Data sheet? For
example the user has to enter a unique number into a cell "E1" on the CSV
Data worksheet. I would like the name of the CSV file to start with that
number in "E1" then followed by the date like you wrote it. Is that
possible?

"Ron de Bruin" wrote:

Try this one to save the file in C:\

Sub Sheet_CSV_File()
Dim wb As Workbook
Dim strdate As String
Dim Fname As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Fname = "C:\Part of " & ThisWorkbook.Name _
& " " & strdate & ".csv"

Application.ScreenUpdating = False
Sheets("CSV Data").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



"Husker87" wrote in message ...
I have a workbook with several worksheets. I want to record a macro that
will save one tab, "CSV Data" as its own csv file to another location. Any
ideas?








  #6   Report Post  
Husker87
 
Posts: n/a
Default

Worked GREAT. Thanks again. btw, why would you not want to save it to a
floppy but the c: drive first?

"Ron de Bruin" wrote:

Hi

First of all never save to a floppy this way.
Always save to C:\ and copy manual to A


Try this

Sub Sheet_CSV_File_2()
Dim wb As Workbook
Dim strdate As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Application.ScreenUpdating = False
Sheets("CSV Data").Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & wb.Sheets(1).Range("E1") & " " & _
strdate & ".csv", FileFormat:=xlCSV
.Close False
End With
Application.ScreenUpdating = True
End Sub


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



"Husker87" wrote in message ...
Short follow up... btw this worked great. I changed the C: to A: so I could
save it to a disk. Here is my follow-up... can I change your code that
names the file to include the content of a cell on the CSV Data sheet? For
example the user has to enter a unique number into a cell "E1" on the CSV
Data worksheet. I would like the name of the CSV file to start with that
number in "E1" then followed by the date like you wrote it. Is that
possible?

"Ron de Bruin" wrote:

Try this one to save the file in C:\

Sub Sheet_CSV_File()
Dim wb As Workbook
Dim strdate As String
Dim Fname As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Fname = "C:\Part of " & ThisWorkbook.Name _
& " " & strdate & ".csv"

Application.ScreenUpdating = False
Sheets("CSV Data").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



"Husker87" wrote in message ...
I have a workbook with several worksheets. I want to record a macro that
will save one tab, "CSV Data" as its own csv file to another location. Any
ideas?






  #7   Report Post  
Ron de Bruin
 
Posts: n/a
Default

Good morning

Worked GREAT. Thanks again. btw, why would you not want to save it to a
floppy but the c: drive first?


The chance of file Corruption is big




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



"Husker87" wrote in message ...
Worked GREAT. Thanks again. btw, why would you not want to save it to a
floppy but the c: drive first?

"Ron de Bruin" wrote:

Hi

First of all never save to a floppy this way.
Always save to C:\ and copy manual to A


Try this

Sub Sheet_CSV_File_2()
Dim wb As Workbook
Dim strdate As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Application.ScreenUpdating = False
Sheets("CSV Data").Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & wb.Sheets(1).Range("E1") & " " & _
strdate & ".csv", FileFormat:=xlCSV
.Close False
End With
Application.ScreenUpdating = True
End Sub


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



"Husker87" wrote in message ...
Short follow up... btw this worked great. I changed the C: to A: so I could
save it to a disk. Here is my follow-up... can I change your code that
names the file to include the content of a cell on the CSV Data sheet? For
example the user has to enter a unique number into a cell "E1" on the CSV
Data worksheet. I would like the name of the CSV file to start with that
number in "E1" then followed by the date like you wrote it. Is that
possible?

"Ron de Bruin" wrote:

Try this one to save the file in C:\

Sub Sheet_CSV_File()
Dim wb As Workbook
Dim strdate As String
Dim Fname As String

strdate = Format(Now, "dd-mm-yy h-mm-ss")

Fname = "C:\Part of " & ThisWorkbook.Name _
& " " & strdate & ".csv"

Application.ScreenUpdating = False
Sheets("CSV Data").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



"Husker87" wrote in message ...
I have a workbook with several worksheets. I want to record a macro that
will save one tab, "CSV Data" as its own csv file to another location. Any
ideas?








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
cannot copy a worksheet within a workbook ROBERT P. SANDOZ Excel Discussion (Misc queries) 3 August 16th 05 04:53 PM
I can't get a worksheet to copy onto the workbook KCoyne Excel Worksheet Functions 3 March 12th 05 04:09 PM
Copy from worksheet to another x times Union70 Excel Discussion (Misc queries) 0 March 7th 05 09:03 PM
copy COLUMN from 1 worksheet to another (in a different workbook) DavidB Excel Discussion (Misc queries) 3 January 15th 05 02:47 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM


All times are GMT +1. The time now is 02:12 PM.

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

About Us

"It's about Microsoft Excel"