VBA to map workbook sheets to folders with the same name as the sheet

JasonCorbett

New Member
Joined
Feb 19, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello!

I am currently using a Sub that splits each worksheet from a single active workbook into the same folder that the single active workbook is located.

I would instead like to map the sheets to a folder with the same name as the sheet itself. Sheet ABC to Folder ABC, so on and so forth.

Here is the current code:

'Code Created by Sumit Bansal
Sub SplitEachWorksheet()
Dim FPath As String
FPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Sheets
ws.Copy
Application.ActiveWorkbook.SaveAs Filename:=FPath & "\" & ws.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

------------

I have tried to update the .SaveAs path to no avail and keep getting error messages. Any help would be greatly appreciated.

Thank you!
 

Attachments

  • Path.png
    Path.png
    130.6 KB · Views: 12

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Thanks for the quick reply Johnny!

The folders do exist, but the code that I’m using (credit: Sunny Bansil) is saving the files to the same folder as the active workbook.

I have created sub folders as shown on my screenshot, and want to save Sheet ABC to Folder ABC after the macro splits them from the original workbook.

Hope that makes sense? Thank you
 
Upvote 0
maybe
Application.ActiveWorkbook.SaveAs Filename:=FPath & "\" & ws.Name & "\" & ws.Name & ".xlsx"
 
Upvote 0
Solution
Thank you Micron. I will check that output when I return this evening and let you know how it goes.

Happy Saturday,
Jay
 
Upvote 0

Forum statistics

Threads
1,215,561
Messages
6,125,538
Members
449,236
Latest member
Afua

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