Split a workbook into multiple workbooks and save into new folder

mikeyeye

New Member
Joined
Aug 11, 2023
Messages
3
Office Version
  1. 2007
Platform
  1. Windows
Good Day,

for assistance please, kindly help me what is the code to save the output file to a new folder. below is the code that i used right now.

Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Appreciate your help on this.

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You will need to change the location, which you have declared as 'xPath'. Currently it is saving the file inside the directory of the original.

VBA Code:
Dim xPath As String
xPath = Application.ActiveWorkbook.Path

could be (as an example)

VBA Code:
Dim xPath As String
xPath = "C:\Users\USER\Documents\"

------------
PS. It makes it easier to read, and you will get more help, if you wrap your code in the 'VBA' brackets. You can do that by highlighting your code and clicking the 'VBA' icon at the top of the Post box when you type.
 
Upvote 0
Solution
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Split a workbook into multiple workbooks and save into new folder
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
You will need to change the location, which you have declared as 'xPath'. Currently it is saving the file inside the directory of the original.

VBA Code:
Dim xPath As String
xPath = Application.ActiveWorkbook.Path

could be (as an example)

VBA Code:
Dim xPath As String
xPath = "C:\Users\USER\Documents\"

------------
PS. It makes it easier to read, and you will get more help, if you wrap your code in the 'VBA' brackets. You can do that by highlighting your code and clicking the 'VBA' icon at the top of the Post box when you type.
thanks it's work!!!
 
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,076
Members
453,020
Latest member
mattg2448

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