ollyhughes1982
Well-known Member
- Joined
- Nov 27, 2018
- Messages
- 793
- Office Version
- 365
- Platform
- MacOS
Hi,
I have the following code, which saves / exports all worksheets within a single .xlsx file to separate .xlsx files in the same file path location:
Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ActiveWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs FileName:=xPath & Application.PathSeparator & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Is there a way that I can amend this to work so that it saves the files in .csv format instead. I have tried a few things (see a related post here: VBA to save all worksheets as separate .xlsx files - macOS), but none have worked so far - despite working for the suggesting user on Windows OS.
Below is one of the suggestions, but despite working on Windows, it didn't work for my Mac. Guessing there must be a different file type part to make it work, rather than 'xlCSVUTF8'.
Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ActiveWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs FileName:=xPath & Application.PathSeparator & xWs.Name, FileFormat:=xlCSVUTF8
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Thanks in advance!
I have the following code, which saves / exports all worksheets within a single .xlsx file to separate .xlsx files in the same file path location:
Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ActiveWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs FileName:=xPath & Application.PathSeparator & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Is there a way that I can amend this to work so that it saves the files in .csv format instead. I have tried a few things (see a related post here: VBA to save all worksheets as separate .xlsx files - macOS), but none have worked so far - despite working for the suggesting user on Windows OS.
Below is one of the suggestions, but despite working on Windows, it didn't work for my Mac. Guessing there must be a different file type part to make it work, rather than 'xlCSVUTF8'.
Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ActiveWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs FileName:=xPath & Application.PathSeparator & xWs.Name, FileFormat:=xlCSVUTF8
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Thanks in advance!