Macro to save current tab as CSV

biglb79

Active Member
Joined
Oct 17, 2007
Messages
299
is there a macro someone could help me write that would take the current tab and save it down into the folder on this path using the current tab's name as a CSV file?

H:\SAP JEs
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this

VBA Code:
Sub Macro1()
  Dim wPath As String, wFile As String
  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
  wPath = "H:\SAP JEs\"
  wFile = ActiveSheet.Name & ".csv"
  ActiveSheet.Copy
  ActiveWorkbook.SaveAs Filename:=wPath & wFile, FileFormat:=xlCSV, CreateBackup:=False
  ActiveWorkbook.Close False
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0
do you know why it would be erroring out if I just deleted some of the data or changed some of it? I would think that the file would still save as a CSV file

Sub Macro1()
Dim wPath As String, wFile As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
wPath = "H:\SAP JEs\"
wFile = ActiveSheet.Name & ".csv"
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=wPath & wFile, FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close False
End Sub
 
Upvote 0
do you know why it would be erroring out if I just deleted some of the data or changed some of it? I would think that the file would still save as a CSV file
I don't understand the question, can you explain?
 
Upvote 0
I don't understand the question, can you explain?

it was having the debugger come up. I changed the tab name and it worked so perhaps it had a name that it didn't like? I thought it was maybe because a version of that CSV was already saved out there but it still did it after I deleted the file. when I clicked on debug the bold line above was highlighted
 
Upvote 0
it was having the debugger come up. I changed the tab name and it worked so perhaps it had a name that it didn't like? I thought it was maybe because a version of that CSV was already saved out there but it still did it after I deleted the file. when I clicked on debug the bold line above was highlighted
It may be that he had a reserved word or some symbol that is not allowed. Or the file was open.
What did the error say?
What did you have of name on the sheet?
 
Upvote 0
It may be that he had a reserved word or some symbol that is not allowed. Or the file was open.
What did the error say?
What did you have of name on the sheet?


I can't remember what it said but the tab was payroll 11.21.2019 and when I took out the periods it worked just like before so maybe that's why?
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

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