Macro to save mutliple sheets as CSV - no file extension on files

alex0182828

Board Regular
Joined
Jun 20, 2012
Messages
87
Office Version
  1. 365
Platform
  1. MacOS
Im using the below code on Excel mac but the files are created without any file extension can anyone help add .csv
Please also can i put the date in the file name like 280223 for the 28th feb 23 in front of the workbook name.

Thanks. ALex

Rich (BB code):
Sub asdf()
Dim ws As Worksheet, newWb As Workbook

Application.ScreenUpdating = False
For Each ws In Sheets(Array("EID Upload", "Wages with Locals Upload", "Wages without Local Upload"))
   ws.Copy
   Set newWb = ActiveWorkbook
   With newWb
      .SaveAs ws.Name, xlCSV
      .Close (False)
   End With
Next ws
Application.ScreenUpdating = True

End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
File is saved with extension in pc; I'm not familiar with Mac. Are you sure that your settings are set to not show extensions for known types? What happens when you try to open the created file? If it opens, then maybe no problem (or check settings). As for date in file, perhaps add
Dim strName As String
and alter this part
VBA Code:
   Set newWb = ActiveWorkbook
   strName = Format(Day(Date), "00") & Format(Month(Date), "00") & Year(Date) & ws.Name
   With newWb
      .SaveAs strName, xlCSV
      .Close (False)
   End With
 
Upvote 0
Thanks code is great for date in file. I had to add & ".csv" to the end to get the extension correct. Nothing was set and i was viewing my foldering with extensions showning.

Sharing final code below for anyone that this helps

Rich (BB code):
Sub savetoseperates()
Dim ws As Worksheet, newWb As Workbook

Application.ScreenUpdating = False
For Each ws In Sheets(Array("sheet1", "sheet2", "sheet3"))
   ws.Copy
   Set newWb = ActiveWorkbook
   strName = Format(Day(Date), "00") & Format(Month(Date), "00") & Year(Date) & ws.Name & ".csv"
   With newWb
      .SaveAs strName, xlCSV
      .Close (False)
   End With
Next ws
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Odd. I tried that as strName & ".csv" and I ended up with FileName.csv.csv
Must be a Mac thing.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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