Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Macro to copy sheets to another workbook fails after about 45 copi

I created a macro to quickly copy sheets from a series of workbooks
containing 5-15 sheets each to a master "All" workbook. This works fine for
several workbooks, but then, sometimes at the beginning of a workbook copy
and sometimes in the middle, it gives an error €śCopy method of Worksheet
class failed€ť, and the €śSheets(cnt).Copy After:=Workbooks(This).Sheets(xx)€ť
statement is highlighted in yellow. At this point a total of roughly xx = 45
sheets have been copied from several workbooks.

In order to get this to work again, I need to close the €śAll€ť workbook and
re-open it. Then I can continue to use the macro for several more workbook
combines until I get the error again. Why is this happening?

Sub Combine() 'macro starts in a workbook that is being copied from.
Dim x, xx, cnt
Dim This As String
Dim All As String
All = "Data - CSR Monthly Report - Sep2009final.xls" 'destination workbook
x = Sheets.Count
This = ActiveWorkbook.Name
For cnt = 1 To x
Workbooks(This).Activate
xx = Workbooks(All).Sheets.Count
Sheets(cnt).Copy After:=Workbooks(All).Sheets(xx)
Next
Workbooks(This).Activate
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro to copy sheets to another workbook fails after about 45 copi

Use the workbook object...Also you dont need to loop...Try the below and
feedback

Sub Combine()
Dim wbThis As Workbook, wbDest As Workbook
Set wbDest = Workbooks("Data - CSR Monthly Report - Sep2009final.xls")
Set wbThis = ActiveWorkbook
wbThis.Sheets.Copy After:=wbDest.Sheets(wbDest.Sheets.Count)

''OR using a loop
'For Each ws In wbThis
' ws.Copy After:=wbDest.Sheets(wb.Sheets.Count)
'Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"AZSteve" wrote:

I created a macro to quickly copy sheets from a series of workbooks
containing 5-15 sheets each to a master "All" workbook. This works fine for
several workbooks, but then, sometimes at the beginning of a workbook copy
and sometimes in the middle, it gives an error €śCopy method of Worksheet
class failed€ť, and the €śSheets(cnt).Copy After:=Workbooks(This).Sheets(xx)€ť
statement is highlighted in yellow. At this point a total of roughly xx = 45
sheets have been copied from several workbooks.

In order to get this to work again, I need to close the €śAll€ť workbook and
re-open it. Then I can continue to use the macro for several more workbook
combines until I get the error again. Why is this happening?

Sub Combine() 'macro starts in a workbook that is being copied from.
Dim x, xx, cnt
Dim This As String
Dim All As String
All = "Data - CSR Monthly Report - Sep2009final.xls" 'destination workbook
x = Sheets.Count
This = ActiveWorkbook.Name
For cnt = 1 To x
Workbooks(This).Activate
xx = Workbooks(All).Sheets.Count
Sheets(cnt).Copy After:=Workbooks(All).Sheets(xx)
Next
Workbooks(This).Activate
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro to copy sheets to another workbook fails after about 45

correction incase you try out the Loop..

For Each ws In wbThis
ws.Copy After:=wbDest.Sheets(wbDest.Sheets.Count)
Next

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Use the workbook object...Also you dont need to loop...Try the below and
feedback

Sub Combine()
Dim wbThis As Workbook, wbDest As Workbook
Set wbDest = Workbooks("Data - CSR Monthly Report - Sep2009final.xls")
Set wbThis = ActiveWorkbook
wbThis.Sheets.Copy After:=wbDest.Sheets(wbDest.Sheets.Count)

''OR using a loop
'For Each ws In wbThis
' ws.Copy After:=wbDest.Sheets(wb.Sheets.Count)
'Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"AZSteve" wrote:

I created a macro to quickly copy sheets from a series of workbooks
containing 5-15 sheets each to a master "All" workbook. This works fine for
several workbooks, but then, sometimes at the beginning of a workbook copy
and sometimes in the middle, it gives an error €śCopy method of Worksheet
class failed€ť, and the €śSheets(cnt).Copy After:=Workbooks(This).Sheets(xx)€ť
statement is highlighted in yellow. At this point a total of roughly xx = 45
sheets have been copied from several workbooks.

In order to get this to work again, I need to close the €śAll€ť workbook and
re-open it. Then I can continue to use the macro for several more workbook
combines until I get the error again. Why is this happening?

Sub Combine() 'macro starts in a workbook that is being copied from.
Dim x, xx, cnt
Dim This As String
Dim All As String
All = "Data - CSR Monthly Report - Sep2009final.xls" 'destination workbook
x = Sheets.Count
This = ActiveWorkbook.Name
For cnt = 1 To x
Workbooks(This).Activate
xx = Workbooks(All).Sheets.Count
Sheets(cnt).Copy After:=Workbooks(All).Sheets(xx)
Next
Workbooks(This).Activate
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to copy sheets to another workbook fails after about 45 copi

See
http://support.microsoft.com/kb/210684/en-us

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"AZSteve" wrote in message
...
I created a macro to quickly copy sheets from a series of workbooks
containing 5-15 sheets each to a master "All" workbook. This works fine
for
several workbooks, but then, sometimes at the beginning of a workbook copy
and sometimes in the middle, it gives an error €śCopy method of Worksheet
class failed€ť, and the €śSheets(cnt).Copy
After:=Workbooks(This).Sheets(xx)€ť
statement is highlighted in yellow. At this point a total of roughly xx =
45
sheets have been copied from several workbooks.

In order to get this to work again, I need to close the €śAll€ť workbook and
re-open it. Then I can continue to use the macro for several more
workbook
combines until I get the error again. Why is this happening?

Sub Combine() 'macro starts in a workbook that is being copied from.
Dim x, xx, cnt
Dim This As String
Dim All As String
All = "Data - CSR Monthly Report - Sep2009final.xls" 'destination
workbook
x = Sheets.Count
This = ActiveWorkbook.Name
For cnt = 1 To x
Workbooks(This).Activate
xx = Workbooks(All).Sheets.Count
Sheets(cnt).Copy After:=Workbooks(All).Sheets(xx)
Next
Workbooks(This).Activate
End Sub


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
Macro to Copy Sheets to new workbook KennyD Excel Discussion (Misc queries) 18 January 31st 10 01:25 PM
HELP! Macro FAILS when I copy the worksheet... Chris M Excel Programming 4 September 17th 06 04:06 PM
macro in copied workbook fails [email protected] Excel Programming 0 April 22nd 06 01:59 PM
Macro to copy sheets from several files into a new workbook. [email protected] Excel Programming 2 November 10th 05 10:45 PM
Sheets select method fails when workbook is opened by another workbook Mike Excel Programming 2 June 8th 04 04:17 AM


All times are GMT +1. The time now is 04:19 AM.

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"