Macro: export current worksheet as CSV file using Save As prompt

dlz217

New Member
Joined
Aug 23, 2013
Messages
49
I have a workbook that has 3 sheets. I have a macro that performs different operations and I'd like to add a step to take the active worksheet, prompt me to save that individual sheet as a CSV file (using the Save As prompt), but not affect the current workbook and continue on with further steps.

I'm able to prompt the Save As dialog, but that changes the file name of the active workbook, which I don't want.

Code:
    MsgBox "Save CSV file."
    Application.Dialogs(xlDialogSaveAs).Show
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try copying the worksheet to a new workbook with:

Code:
ActiveSheet.Copy

then saving ActiveWorkbook as csv (and closing it).
 
Upvote 0
Where am I going wrong here? +PAYE CSV Gen.xlsm is the active workbook.

Code:
    Workbooks.Add
    Set TempFile = ActiveWorkbook
    Windows("+PAYE CSV Gen.xlsm").Activate
    ActiveSheet.Copy Before:=Workbooks(TempFile).Sheets(1)
    MsgBox "Save CSV file."
    Application.Dialogs(xlDialogSaveAs).Show
    ActiveWorkbook.Close
 
Upvote 0
TempFile is a Workbook Object not a string:

Code:
ActiveSheet.Copy Before:=TempFile.Sheets(1)

But you don't need to Add a Workbook. ActiveSheet.Copy (with no arguments) will do that for you.
 
Upvote 0

Forum statistics

Threads
1,222,404
Messages
6,165,853
Members
451,986
Latest member
ExcelIsLove

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