View Full Version : Save one sheet of a work book as .csv?
option 08-11-2008, 01:01 PM Hey guys,
I have a workbook of 8 pages and on the 6th page, all of the information that the user has input is stored there. Once complete, I would like the user to be able to click a button to save a copy of just page 6 as a .csv to another folder. Is this possible? **Note** Pages 4-8 are not visible to the user, so the save button would probably wind up on page 2 of the spreadsheet. Thanks in advance guys!!:o
chergh 08-12-2008, 01:06 AM thisworkbook.worksheets("Page 6").saveas filename:="blah", fileformat:= xlcsv
option 08-12-2008, 06:11 AM tried using that and got an error. could it be because im not specifying the save location?
chergh 08-12-2008, 06:25 AM What was the error message?
option 08-12-2008, 06:37 AM Well, I got it to work now, except its saving the entire workbook.
ThisWorkbook.Worksheets("Var").SaveAs "c:\saveddaily\user" & Format(Date, "mmddyy") & ".csv"
That's what I'm using to save where "Var" is the sheet I need to save.
chergh 08-12-2008, 06:40 AM you've not specified the file format tacking .csv onto the end isn't specifying the format you need to include:
fileformat:= xlcsv
DreamGenius 08-12-2008, 06:58 AM To qualify what @chergh has said, you'll probably also need to suppress warnings as, when saving a multi-sheet Excel file to CSV, you'll get a warning that CSV doesn't support multiple sheets.
Also, the file the user will have open then will be the CSV, not the XLS, file. Be sure to save any changes that they've made and you want to keep in the XLS file before doing the Save As!
option 08-12-2008, 07:03 AM That's the whole thing...we don't want to save anything in the xls. Hence saving the csv. As far as not specifying the ".csv" , thats at the very end of my line of code (which works btw). I get no warnings when I save using my code. It saves the modified xls as a csv. Maybe I'm asking the question wrong, but I don't know how else to word it...
chergh 08-12-2008, 07:23 AM actually I made a mistake in the fileformat it should be
fileformat:= xlCSVMSDOS
Just putting a csv file extension is not specifying the format, there are a lot of csv formats out there
Your code needs to be:
ThisWorkbook.Worksheets("Var").SaveAs filename:="c:\saveddaily\user" & Format(Date, "mmddyy") , fileformat:=xlCSVMSDOS
option 08-12-2008, 08:09 AM That still saves the entire workbook though.
chergh 08-12-2008, 08:11 AM It only saves the specified worksheet for me.
option 08-12-2008, 08:13 AM Hmm...it's saving the whole workbook and setting focus to that sheet on open for me.
chergh 08-12-2008, 08:17 AM Once I close and reopen the file it only contains one worksheet for me.
option 08-12-2008, 12:14 PM Hmm...not me, and we're using the same code......I've tried on 3 different machines all with the same result.
chergh 08-13-2008, 12:50 AM Have you tried creating a new workbook and creating a sub with only that 1 line of vba in it?
option 08-13-2008, 10:40 AM Fixed it. Thanks a ton for being so helpful and patient!!
|