Hello,
I found VBA code online that splits a workbooks sheets into individual files and saves all those files in a folder with the same name as the file. The Macro is working as intended but I'm having difficulty making a few minor changes to the code to customize it to my liking. I want to be able to change the name of the output folder the macro creates to what ever is in cell A1. I also only want to save off sheets 15,16,17,18,19,20 and 21. The code is below. Any input is greatly appreciated.
I found VBA code online that splits a workbooks sheets into individual files and saves all those files in a folder with the same name as the file. The Macro is working as intended but I'm having difficulty making a few minor changes to the code to customize it to my liking. I want to be able to change the name of the output folder the macro creates to what ever is in cell A1. I also only want to save off sheets 15,16,17,18,19,20 and 21. The code is below. Any input is greatly appreciated.
Code:
Option Explicit
Sub SplitBook()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
MyFilePath$ = ActiveWorkbook.Path & "\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
MkDir MyFilePath '<< create a folder
For N = 1 To Sheets.Count
Sheets(N).Activate
SheetName = ActiveSheet.Name
Cells.Copy
Workbooks.Add (xlWBATWorksheet)
With ActiveWorkbook
With .ActiveSheet
.Paste
.Name = SheetName
[A1].Select
End With
'save book in this folder
.SaveAs Filename:=MyFilePath _
& "\" & SheetName & ".xlsx"
.Close SaveChanges:=True
End With
.CutCopyMode = False
Next
End With
Sheet1.Activate
End Sub