macro for saving tab as CSV

biglb79

Active Member
Joined
Oct 17, 2007
Messages
299
is there a macro I can use that will save my current tab down to my desktop as a CSV file using the file name as the tab name?
 

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.
Have you tried recording a macro doing what you want?

Once you have the recorded code, you can use the sheet name as the filename (ActiveSheet.Name).

HTH
 
Upvote 0
I've done that before. I just didn't know you could save the new tab down onto my desktop as part of the recording process still. I tried and it's giving me an error

Sub Macro1()
'
' Macro1 Macro
'

'
Range("A6:B6").Select
Range("B6").Activate
End Sub
Sub Macro2()
'
' Macro2 Macro
'

'
Sheets("Payroll JE 09.13.18").Select
Sheets("Payroll JE 09.13.18").Copy
Windows("homework for Kim.xlsm").Activate
Windows("Book3").Activate
ChDir "C:\Users\bbeachler\Desktop"
ActiveWorkbook.SaveAs Filename:="C:\Users\bbeachler\Desktop\Book3.txt", _
FileFormat:=xlText, CreateBackup:=False
End Sub
 
Upvote 0
What's the error?

Try:

ActiveWorkbook.SaveAs Filename:="C:\Users\bbeachler\Desktop" & ActiveSheet.Name & ".txt", _
FileFormat:=xlText, CreateBackup:=False
 
Upvote 0
is there a macro I can use that will save my current tab down to my desktop as a CSV file using the file name as the tab name?

I assume you mean use the tab name as the file name. Try this:

Code:
Public Sub Save_Sheet_As_CSV()
    
    Dim fileName As String
    
    With ActiveSheet
        fileName = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator & .Name
        .Copy
    End With
    
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs fileName, FileFormat:=xlCSV
    ActiveWorkbook.Close False
    Application.DisplayAlerts = True

End Sub
 
Upvote 0
that's perfect, thanks!

I assume you mean use the tab name as the file name. Try this:

Code:
Public Sub Save_Sheet_As_CSV()
    
    Dim fileName As String
    
    With ActiveSheet
        fileName = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator & .Name
        .Copy
    End With
    
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs fileName, FileFormat:=xlCSV
    ActiveWorkbook.Close False
    Application.DisplayAlerts = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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