Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Split Workbook - improved code required

Hi,

I am using the following code to split one workbook with multipl
worksheets into - many workbooks.


Sub SplitSheets()
Dim W As Worksheet
For Each W In Worksheets
W.SaveAs ActiveWorkbook.Path & "/" & W.Name
Next W
End Sub


The problem i have is this takes several minutes to run and it doesn'
actually work - it replicates the original.

Could i ask for some help optimising the code please!

thanks,
Hamis

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Split Workbook - improved code required



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"HamishM " wrote in message
...
Hi,

I am using the following code to split one workbook with multiple
worksheets into - many workbooks.


Sub SplitSheets()
Dim W As Worksheet
For Each W In Worksheets
W.SaveAs ActiveWorkbook.Path & "/" & W.Name
Next W
End Sub


The problem i have is this takes several minutes to run and it doesn't
actually work - it replicates the original.

Could i ask for some help optimising the code please!

thanks,
Hamish


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Split Workbook - improved code required

Hamish,

Give this a try

Dim W As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each W In Worksheets
W.Copy
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "/" & W.Name
activeworkbok.Close
Next W
Application.DisplayAlerts = True
Application.ScreenUpdating = True


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"HamishM " wrote in message
...
Hi,

I am using the following code to split one workbook with multiple
worksheets into - many workbooks.


Sub SplitSheets()
Dim W As Worksheet
For Each W In Worksheets
W.SaveAs ActiveWorkbook.Path & "/" & W.Name
Next W
End Sub


The problem i have is this takes several minutes to run and it doesn't
actually work - it replicates the original.

Could i ask for some help optimising the code please!

thanks,
Hamish


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Split Workbook - improved code required

Thanks Bob,

Seems to work alright for the first three sheets then runtime error
occurs on the copy of worksheet.

any ideas?


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Split Workbook - improved code required

Hamish,

I just tried it with 7 worksheets, and all 7 were saved fine.

Nothing off the top, I'll post back if I think of anything.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"HamishM " wrote in message
...
Thanks Bob,

Seems to work alright for the first three sheets then runtime error
occurs on the copy of worksheet.

any ideas?


---
Message posted from http://www.ExcelForum.com/





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Split Workbook - improved code required

Bob,

this is the code i'm using.....

Sub SplitSheets()
Dim W As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each W In Worksheets
W.Copy
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "/" & W.Name
ActiveWorkbook.Close
Next W
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Su

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Split Workbook - improved code required

Yeah, it's identical.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"HamishM " wrote in message
...
Bob,

this is the code i'm using.....

Sub SplitSheets()
Dim W As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each W In Worksheets
W.Copy
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "/" & W.Name
ActiveWorkbook.Close
Next W
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


---
Message posted from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Split Workbook - improved code required

I've now tried it on several other workbooks and it seems to be working
No idea what was wrong with the other but am happy now!

Just another thought - if i only wanted select sheets to be split out
can i create a list in the code? (or select sheets and then run th
macro?

--
Message posted from http://www.ExcelForum.com

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Split Workbook - improved code required

Sure

change
For Each W In Worksheets

to
for each W in Worksheets(Array("sheet1","Sheet3", _
"Sheet5","sheet7"))

or

for each W in Worksheets(Array(1,3,5,7))

--
Regards,
Tom Ogilvy


HamishM wrote in message
...
I've now tried it on several other workbooks and it seems to be working.
No idea what was wrong with the other but am happy now!

Just another thought - if i only wanted select sheets to be split out,
can i create a list in the code? (or select sheets and then run the
macro?)


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Another VB Code Required TGV Excel Discussion (Misc queries) 7 February 7th 09 07:21 AM
VB Code Required TGV Excel Discussion (Misc queries) 3 February 6th 09 05:31 PM
Improved printing of VBA code? Revolvr[_2_] Excel Programming 0 September 2nd 03 05:22 PM
Improved printing of VBA code? steve Excel Programming 0 August 29th 03 08:42 PM


All times are GMT +1. The time now is 12:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"