Saves Individual Worksheets as Workbooks in destination folder
up vote
0
down vote
favorite
This code takes, on average, 6 minutes to fully run with the workbook I am using. The workbook currently has 148 worksheets and will grow consistently with time.
I am curious if there is a way to edit the code from doing the task one worksheet at a time; and, instead complete the task all in one moment. In my mind, the code would run for a much shorter time and then populate all the worksheets as separate workbooks in the file destination at the same time. The worksheets would also not "pop-up" before saving themselves in the destination folder. Much like stopping screen updating and automatic calculations making a world of difference - except that did not work with this code.
Sub SaveFilesInFolder()
'
'Macro for saving each worksheet as a workbook in a destination folder
'
'
Dim sh As Worksheet
Dim wb As Workbook
For Each sh In Worksheets
SheetName = sh.Name
sh.Copy
With ActiveWorkbook
.SaveAs FileName:="FolderDestination" & SheetName
.Close SaveChanges:=True
End With
Next sh
End Sub
Any suggestions are appreciated.
vba excel
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
up vote
0
down vote
favorite
This code takes, on average, 6 minutes to fully run with the workbook I am using. The workbook currently has 148 worksheets and will grow consistently with time.
I am curious if there is a way to edit the code from doing the task one worksheet at a time; and, instead complete the task all in one moment. In my mind, the code would run for a much shorter time and then populate all the worksheets as separate workbooks in the file destination at the same time. The worksheets would also not "pop-up" before saving themselves in the destination folder. Much like stopping screen updating and automatic calculations making a world of difference - except that did not work with this code.
Sub SaveFilesInFolder()
'
'Macro for saving each worksheet as a workbook in a destination folder
'
'
Dim sh As Worksheet
Dim wb As Workbook
For Each sh In Worksheets
SheetName = sh.Name
sh.Copy
With ActiveWorkbook
.SaveAs FileName:="FolderDestination" & SheetName
.Close SaveChanges:=True
End With
Next sh
End Sub
Any suggestions are appreciated.
vba excel
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
You declarewb
but do not use it. Perhaps this provides a clue.
– AJD
Mar 12 at 18:51
Just an aside question. Why on earth would anyone think it is a good idea to make a 148sheet workbook?
– Maarten Fabré
Oct 9 at 12:48
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This code takes, on average, 6 minutes to fully run with the workbook I am using. The workbook currently has 148 worksheets and will grow consistently with time.
I am curious if there is a way to edit the code from doing the task one worksheet at a time; and, instead complete the task all in one moment. In my mind, the code would run for a much shorter time and then populate all the worksheets as separate workbooks in the file destination at the same time. The worksheets would also not "pop-up" before saving themselves in the destination folder. Much like stopping screen updating and automatic calculations making a world of difference - except that did not work with this code.
Sub SaveFilesInFolder()
'
'Macro for saving each worksheet as a workbook in a destination folder
'
'
Dim sh As Worksheet
Dim wb As Workbook
For Each sh In Worksheets
SheetName = sh.Name
sh.Copy
With ActiveWorkbook
.SaveAs FileName:="FolderDestination" & SheetName
.Close SaveChanges:=True
End With
Next sh
End Sub
Any suggestions are appreciated.
vba excel
This code takes, on average, 6 minutes to fully run with the workbook I am using. The workbook currently has 148 worksheets and will grow consistently with time.
I am curious if there is a way to edit the code from doing the task one worksheet at a time; and, instead complete the task all in one moment. In my mind, the code would run for a much shorter time and then populate all the worksheets as separate workbooks in the file destination at the same time. The worksheets would also not "pop-up" before saving themselves in the destination folder. Much like stopping screen updating and automatic calculations making a world of difference - except that did not work with this code.
Sub SaveFilesInFolder()
'
'Macro for saving each worksheet as a workbook in a destination folder
'
'
Dim sh As Worksheet
Dim wb As Workbook
For Each sh In Worksheets
SheetName = sh.Name
sh.Copy
With ActiveWorkbook
.SaveAs FileName:="FolderDestination" & SheetName
.Close SaveChanges:=True
End With
Next sh
End Sub
Any suggestions are appreciated.
vba excel
vba excel
asked Mar 12 at 18:42
Sean Pakulski
1
1
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
You declarewb
but do not use it. Perhaps this provides a clue.
– AJD
Mar 12 at 18:51
Just an aside question. Why on earth would anyone think it is a good idea to make a 148sheet workbook?
– Maarten Fabré
Oct 9 at 12:48
add a comment |
You declarewb
but do not use it. Perhaps this provides a clue.
– AJD
Mar 12 at 18:51
Just an aside question. Why on earth would anyone think it is a good idea to make a 148sheet workbook?
– Maarten Fabré
Oct 9 at 12:48
You declare
wb
but do not use it. Perhaps this provides a clue.– AJD
Mar 12 at 18:51
You declare
wb
but do not use it. Perhaps this provides a clue.– AJD
Mar 12 at 18:51
Just an aside question. Why on earth would anyone think it is a good idea to make a 148sheet workbook?
– Maarten Fabré
Oct 9 at 12:48
Just an aside question. Why on earth would anyone think it is a good idea to make a 148sheet workbook?
– Maarten Fabré
Oct 9 at 12:48
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
What you're looking for is to turn off screenupdating, turn off alerts and auto-save and close.
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close False
So, like this -
Option Explicit
Sub SplitSheetsToBooks()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Const PATH_TO As String = "C:TEMP"
Const EXCEL_EXTENTION As String = ".xlsx"
Dim index As Long
Dim numberOfSheets As Long
Dim targetSheet As Worksheet
numberOfSheets = ThisWorkbook.Sheets.Count
For index = 1 To numberOfSheets
Set targetSheet = ThisWorkbook.Sheets(index)
targetSheet.Copy
ActiveWorkbook.SaveAs PATH_TO & targetSheet.Name & EXCEL_EXTENTION
ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
The above code works exactly how I imagined; however, there is an issue I cannot figure out. The files do not follow the PATH_TO, they instead save to my desktop with the filename "TestSheet1". I have no idea why and I can't see anything in the code that would be causing this.
– Sean Pakulski
Mar 13 at 14:56
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
What you're looking for is to turn off screenupdating, turn off alerts and auto-save and close.
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close False
So, like this -
Option Explicit
Sub SplitSheetsToBooks()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Const PATH_TO As String = "C:TEMP"
Const EXCEL_EXTENTION As String = ".xlsx"
Dim index As Long
Dim numberOfSheets As Long
Dim targetSheet As Worksheet
numberOfSheets = ThisWorkbook.Sheets.Count
For index = 1 To numberOfSheets
Set targetSheet = ThisWorkbook.Sheets(index)
targetSheet.Copy
ActiveWorkbook.SaveAs PATH_TO & targetSheet.Name & EXCEL_EXTENTION
ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
The above code works exactly how I imagined; however, there is an issue I cannot figure out. The files do not follow the PATH_TO, they instead save to my desktop with the filename "TestSheet1". I have no idea why and I can't see anything in the code that would be causing this.
– Sean Pakulski
Mar 13 at 14:56
add a comment |
up vote
0
down vote
What you're looking for is to turn off screenupdating, turn off alerts and auto-save and close.
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close False
So, like this -
Option Explicit
Sub SplitSheetsToBooks()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Const PATH_TO As String = "C:TEMP"
Const EXCEL_EXTENTION As String = ".xlsx"
Dim index As Long
Dim numberOfSheets As Long
Dim targetSheet As Worksheet
numberOfSheets = ThisWorkbook.Sheets.Count
For index = 1 To numberOfSheets
Set targetSheet = ThisWorkbook.Sheets(index)
targetSheet.Copy
ActiveWorkbook.SaveAs PATH_TO & targetSheet.Name & EXCEL_EXTENTION
ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
The above code works exactly how I imagined; however, there is an issue I cannot figure out. The files do not follow the PATH_TO, they instead save to my desktop with the filename "TestSheet1". I have no idea why and I can't see anything in the code that would be causing this.
– Sean Pakulski
Mar 13 at 14:56
add a comment |
up vote
0
down vote
up vote
0
down vote
What you're looking for is to turn off screenupdating, turn off alerts and auto-save and close.
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close False
So, like this -
Option Explicit
Sub SplitSheetsToBooks()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Const PATH_TO As String = "C:TEMP"
Const EXCEL_EXTENTION As String = ".xlsx"
Dim index As Long
Dim numberOfSheets As Long
Dim targetSheet As Worksheet
numberOfSheets = ThisWorkbook.Sheets.Count
For index = 1 To numberOfSheets
Set targetSheet = ThisWorkbook.Sheets(index)
targetSheet.Copy
ActiveWorkbook.SaveAs PATH_TO & targetSheet.Name & EXCEL_EXTENTION
ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
What you're looking for is to turn off screenupdating, turn off alerts and auto-save and close.
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close False
So, like this -
Option Explicit
Sub SplitSheetsToBooks()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Const PATH_TO As String = "C:TEMP"
Const EXCEL_EXTENTION As String = ".xlsx"
Dim index As Long
Dim numberOfSheets As Long
Dim targetSheet As Worksheet
numberOfSheets = ThisWorkbook.Sheets.Count
For index = 1 To numberOfSheets
Set targetSheet = ThisWorkbook.Sheets(index)
targetSheet.Copy
ActiveWorkbook.SaveAs PATH_TO & targetSheet.Name & EXCEL_EXTENTION
ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
answered Mar 12 at 23:23
Raystafarian
5,7941048
5,7941048
The above code works exactly how I imagined; however, there is an issue I cannot figure out. The files do not follow the PATH_TO, they instead save to my desktop with the filename "TestSheet1". I have no idea why and I can't see anything in the code that would be causing this.
– Sean Pakulski
Mar 13 at 14:56
add a comment |
The above code works exactly how I imagined; however, there is an issue I cannot figure out. The files do not follow the PATH_TO, they instead save to my desktop with the filename "TestSheet1". I have no idea why and I can't see anything in the code that would be causing this.
– Sean Pakulski
Mar 13 at 14:56
The above code works exactly how I imagined; however, there is an issue I cannot figure out. The files do not follow the PATH_TO, they instead save to my desktop with the filename "TestSheet1". I have no idea why and I can't see anything in the code that would be causing this.
– Sean Pakulski
Mar 13 at 14:56
The above code works exactly how I imagined; however, there is an issue I cannot figure out. The files do not follow the PATH_TO, they instead save to my desktop with the filename "TestSheet1". I have no idea why and I can't see anything in the code that would be causing this.
– Sean Pakulski
Mar 13 at 14:56
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f189427%2fsaves-individual-worksheets-as-workbooks-in-destination-folder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You declare
wb
but do not use it. Perhaps this provides a clue.– AJD
Mar 12 at 18:51
Just an aside question. Why on earth would anyone think it is a good idea to make a 148sheet workbook?
– Maarten Fabré
Oct 9 at 12:48