Forum Discussion
CreativeSteph
Jun 15, 2022Copper Contributor
Excel VBA to put each sheet into an individual Excel file (split book)
Hello- I'm trying to save a new Excel file for each sheet in an Excel file. I found this code, but it only works if the code is written into the VBA module of the Excel I wish to parse. I want ...
- Jun 15, 2022
CreativeSteph I haven't tested it, but assuming the code itself works it looks like you might only need to change the one part I highlighted in red:
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
mtarler
Jun 15, 2022Silver Contributor
CreativeSteph I haven't tested it, but assuming the code itself works it looks like you might only need to change the one part I highlighted in red:
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
CreativeSteph
Jun 15, 2022Copper Contributor
Thanks so much mtarler! It works! One little thing can throw off the whole project!