ManhattanJM
New Member
- Joined
- Feb 19, 2022
- Messages
- 6
- Office Version
- 2016
- Platform
- MacOS
Hi,
I'm trying to take a workbook and separate all of its sheets into new, inidividual workbooks and save them down in a folder with the current name of the sheet. I found code online (below) to do this, but I'm stumped with a run-time error '1004': Method 'SaveAs' of object '_Workbook' failed.
When I hit end and go back to the workbook, all of the sheets are blank (still have names) and don't even have gridlines anymore. When I close out of the workbook, a new file with a generic name opens up with the contents of my first tab but that's it. No additional tabs and nothing is saved down. If someone could point me in the right direction, that would be much appreciated.
Thank you!
I'm trying to take a workbook and separate all of its sheets into new, inidividual workbooks and save them down in a folder with the current name of the sheet. I found code online (below) to do this, but I'm stumped with a run-time error '1004': Method 'SaveAs' of object '_Workbook' failed.
When I hit end and go back to the workbook, all of the sheets are blank (still have names) and don't even have gridlines anymore. When I close out of the workbook, a new file with a generic name opens up with the contents of my first tab but that's it. No additional tabs and nothing is saved down. If someone could point me in the right direction, that would be much appreciated.
Thank you!
VBA Code:
Sub Splitbook()
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 & "\" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub