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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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