MacroProblem-Need Code to Save Worksheet as CSV to Desktop

cgeorge4

Board Regular
Joined
Jul 24, 2011
Messages
91
Hello,

I need a code that will save the active worksheet within my workbook as a CSV file - to my desktop. I'm sorry that I don't currently have a code to show you. I have been everywhere and have not been able to find exactly what I'm needing. I have found some codes but not any with a message box.

I'm using Excel 2010.

I have a workbook that has several worksheets - but I only want to save the worksheet that is currently active - as a CSV file - not the whole workbook.

;)Would it be possible to be prompted by a message box that will ask you how you would like to name the CSV file before that code runs?

In case you need to know, and the number of characters is important - the name of the file would be many characters long. Something like XACCTFEEDIN.8182011.8192011new. If it doesn't matter than that is great!


Thank you so so much,
Juicy,
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi,

Thank you for responding so quickly.

I tried your code several times and it worked to a certain degree.;)

After I ran your code, I went to my desktop and I did find the file - but when I opened it, it was saved with all the sheets that were in my workbook.

....It did have an additional tab with the name I saved file name under - which is great;)....but it is really necessary that only the active sheet be saved as a CSV file. When I'm ready to upload this file - our accounting system won't upload a file with more than one sheet.

Almost there!

Thanks,
Juicy,
 
Upvote 0
Code:
Sub test()
    SaveSheetAsCSV
End Sub

Sub SaveSheetAsCSV(Optional SheetToSave As Worksheet)
    If SheetToSave Is Nothing Then Set SheetToSave = ActiveSheet
    
    SheetToSave.Copy
    
    If Not Application.Dialogs(xlDialogSaveAs).Show(, 6) Then
        ActiveWorkbook.Close SaveChanges:=False
    End If
End Sub
 
Upvote 0
You are Brilliant!!!!!!.:laugh:

I ran your code several times - on workbooks with varying number of worksheets, and it only copied the active worksheet to my desktop.;)


It ran perfectly each time.....thank you sooooooo much,

Juicy, WOW!
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top