Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy method failed

hi all.
I've modifed an existing macro to copy renamed worksheets in to a secondary
workbook.
I've read the KB file from MS that Jim Thomlinson has posted regarding this
issue, and if I understand it correctly the problem mainly occurs when the
user seeks to copy a worksheet in to the same workbook.
My goal is to copy the worksheet in to another, existing workbook.

wks.Copy after:=Workbooks("TROABook-200-299.xlsx").Sheets.count

the response I get from VBA is a 1004 error, stating that the copy method
failed.

My intention is to copy the renamed worksheets into a different workbook
than they are originally in, and at the end.
What am I doing wrong here...?

Thank you.
Your helps are appreciated.
SteveB.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default copy method failed

Replace that line with this.

wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

The current line is returning a number. VBA needs to know what that number
means. So you need to tell VBA that it is a Sheet Index Number. For example,
Sheets(1) or Sheets(5).

Hope this helps! If so, let me know by clicking "YES" below.
--
Cheers,
Ryan


"SteveDB1" wrote:

hi all.
I've modifed an existing macro to copy renamed worksheets in to a secondary
workbook.
I've read the KB file from MS that Jim Thomlinson has posted regarding this
issue, and if I understand it correctly the problem mainly occurs when the
user seeks to copy a worksheet in to the same workbook.
My goal is to copy the worksheet in to another, existing workbook.

wks.Copy after:=Workbooks("TROABook-200-299.xlsx").Sheets.count

the response I get from VBA is a 1004 error, stating that the copy method
failed.

My intention is to copy the renamed worksheets into a different workbook
than they are originally in, and at the end.
What am I doing wrong here...?

Thank you.
Your helps are appreciated.
SteveB.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy method failed

Ryan,
I'm using the code you'd previously given me from this morning's post.
I thought that I could place that line of code immediately beneath the
rename element-- as follows:
-----------------------------------------------------------------------------------------
Select Case wks.Name
Case "Sum", "Summary", "SUM", "summary"
wks.Name = "Sum-" & strWbkName
wks.Copy after:=Sheets(Workbooks("TROABook-200-_
299.xlsx").Sheets.count)



Case "APN"
wks.Name = "APN-" & strWbkName
wks.Copy after:=Sheets(Workbooks("TROABook-200-_
299.xlsx").Sheets.count)

End Select

-------------------------------------------------------------------------------
What did I miss here?
Thank you.


"RyanH" wrote:

Replace that line with this.

wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

The current line is returning a number. VBA needs to know what that number
means. So you need to tell VBA that it is a Sheet Index Number. For example,
Sheets(1) or Sheets(5).

Hope this helps! If so, let me know by clicking "YES" below.
--
Cheers,
Ryan


"SteveDB1" wrote:

hi all.
I've modifed an existing macro to copy renamed worksheets in to a secondary
workbook.
I've read the KB file from MS that Jim Thomlinson has posted regarding this
issue, and if I understand it correctly the problem mainly occurs when the
user seeks to copy a worksheet in to the same workbook.
My goal is to copy the worksheet in to another, existing workbook.

wks.Copy after:=Workbooks("TROABook-200-299.xlsx").Sheets.count

the response I get from VBA is a 1004 error, stating that the copy method
failed.

My intention is to copy the renamed worksheets into a different workbook
than they are originally in, and at the end.
What am I doing wrong here...?

Thank you.
Your helps are appreciated.
SteveB.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default copy method failed

Dim newWB as workbook

Set newWB = Workbooks("TROABook-200-299")

myws.Copy after:=newWB.Worksheets(newWB.Worksheets.Count)

--
HTH,
Barb Reinhardt



"SteveDB1" wrote:

hi all.
I've modifed an existing macro to copy renamed worksheets in to a secondary
workbook.
I've read the KB file from MS that Jim Thomlinson has posted regarding this
issue, and if I understand it correctly the problem mainly occurs when the
user seeks to copy a worksheet in to the same workbook.
My goal is to copy the worksheet in to another, existing workbook.

wks.Copy after:=Workbooks("TROABook-200-299.xlsx").Sheets.count

the response I get from VBA is a 1004 error, stating that the copy method
failed.

My intention is to copy the renamed worksheets into a different workbook
than they are originally in, and at the end.
What am I doing wrong here...?

Thank you.
Your helps are appreciated.
SteveB.

  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy method failed

Barb, and Ryan,

Thank you both for your responses.
I've tried both and get the same error.
subscript out of range.

For Ryan's, the error occurs with the
wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

......:= sheets(...) component.

the line shows 23 sheets, within the (Workbooks(...).sheets.count element,
but once it is "outside" with the sheets(....) portion it gives the subscript
out of range error.


For Barb's, the error occurs
Set newWB = Workbooks("TROABook-200-299")
workbooks(...) = <subscript out of range component.
Barb, what if, instead of a new workbook, it just sets the TROABook as being
active?

I copied your forms and pasted each-- to make sure I didn't mis-type anything.

Again-- thank you both.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default copy method failed

Is the Workbooks("TROABook-200-299.xlsx") open? If it is not open you will
get that error.

Can you post the rest of the code? This will help me to diagnose things.
--
Cheers,
Ryan


"SteveDB1" wrote:

Barb, and Ryan,

Thank you both for your responses.
I've tried both and get the same error.
subscript out of range.

For Ryan's, the error occurs with the
wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

.....:= sheets(...) component.

the line shows 23 sheets, within the (Workbooks(...).sheets.count element,
but once it is "outside" with the sheets(....) portion it gives the subscript
out of range error.


For Barb's, the error occurs
Set newWB = Workbooks("TROABook-200-299")
workbooks(...) = <subscript out of range component.
Barb, what if, instead of a new workbook, it just sets the TROABook as being
active?

I copied your forms and pasted each-- to make sure I didn't mis-type anything.

Again-- thank you both.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy method failed

Yes, the final destination workbook is open.
The entirety of the code is:
------------------------------------------------------------
Sub A1ReNmWksht()

Dim strWbkName As String

Dim wks As Worksheet

' get last 3 characters of the workbook name- minus file extension
strWbkName = Mid(ActiveWorkbook.Name, 5, InStr(ActiveWorkbook.Name, ".")
- 5)


' find worksheet name and change worksheet name if found
For Each wks In ActiveWorkbook.Worksheets
Select Case wks.Name
Case "Sum", "Summary", "SUM", "summary"
wks.Name = "Sum-" & strWbkName
wks.Copy
after:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.count)



Case "APN"
wks.Name = "APN-" & strWbkName
wks.Copy
after:=Worksheets(Workbooks("TROABook-200-299.xlsx").Sheets.count)

End Select

Next wks

End Sub
-------------------------------------------------------------
Again, thank you.



"RyanH" wrote:

Is the Workbooks("TROABook-200-299.xlsx") open? If it is not open you will
get that error.

Can you post the rest of the code? This will help me to diagnose things.
--
Cheers,
Ryan


"SteveDB1" wrote:

Barb, and Ryan,

Thank you both for your responses.
I've tried both and get the same error.
subscript out of range.

For Ryan's, the error occurs with the
wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

.....:= sheets(...) component.

the line shows 23 sheets, within the (Workbooks(...).sheets.count element,
but once it is "outside" with the sheets(....) portion it gives the subscript
out of range error.


For Barb's, the error occurs
Set newWB = Workbooks("TROABook-200-299")
workbooks(...) = <subscript out of range component.
Barb, what if, instead of a new workbook, it just sets the TROABook as being
active?

I copied your forms and pasted each-- to make sure I didn't mis-type anything.

Again-- thank you both.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default copy method failed

I was getting an error on your strWbkName line. Are you? Give this a try:

Sub A1ReNmWksht()

Dim strWbkName As String
Dim wbk As Workbook
Dim wks As Worksheet
Dim lngLastSheet As Long

' get last 3 characters of the workbook name- minus file extension
strWbkName = Mid(ActiveWorkbook.Name, 5, InStr(ActiveWorkbook.Name, ".")
- 5)

' where you want the data to go
Set wbk = Workbooks("TROABook-200-299.xlsx")
lngLastSheet = wbk.Sheets.Count

' find worksheet name and change worksheet name if found
For Each wks In ActiveWorkbook.Worksheets
Select Case wks.Name
Case "Sum", "Summary", "SUM", "summary"
With wks
.Name = "Sum-" & strWbkName
.Copy After:=wbk.Sheets(lngLastSheet)
End With


Case "APN"
With wks
.Name = "APN-" & strWbkName
.Copy After:=wbk.Sheets(lngLastSheet)
End With

End Select
Next wks

End Sub


--
Cheers,
Ryan


"SteveDB1" wrote:

Yes, the final destination workbook is open.
The entirety of the code is:
------------------------------------------------------------
Sub A1ReNmWksht()

Dim strWbkName As String

Dim wks As Worksheet

' get last 3 characters of the workbook name- minus file extension
strWbkName = Mid(ActiveWorkbook.Name, 5, InStr(ActiveWorkbook.Name, ".")
- 5)


' find worksheet name and change worksheet name if found
For Each wks In ActiveWorkbook.Worksheets
Select Case wks.Name
Case "Sum", "Summary", "SUM", "summary"
wks.Name = "Sum-" & strWbkName
wks.Copy
after:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.count)



Case "APN"
wks.Name = "APN-" & strWbkName
wks.Copy
after:=Worksheets(Workbooks("TROABook-200-299.xlsx").Sheets.count)

End Select

Next wks

End Sub
-------------------------------------------------------------
Again, thank you.



"RyanH" wrote:

Is the Workbooks("TROABook-200-299.xlsx") open? If it is not open you will
get that error.

Can you post the rest of the code? This will help me to diagnose things.
--
Cheers,
Ryan


"SteveDB1" wrote:

Barb, and Ryan,

Thank you both for your responses.
I've tried both and get the same error.
subscript out of range.

For Ryan's, the error occurs with the
wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

.....:= sheets(...) component.

the line shows 23 sheets, within the (Workbooks(...).sheets.count element,
but once it is "outside" with the sheets(....) portion it gives the subscript
out of range error.


For Barb's, the error occurs
Set newWB = Workbooks("TROABook-200-299")
workbooks(...) = <subscript out of range component.
Barb, what if, instead of a new workbook, it just sets the TROABook as being
active?

I copied your forms and pasted each-- to make sure I didn't mis-type anything.

Again-- thank you both.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy method failed

Morning Ryan.
That was it. It works great now. THANK YOU!!!!
yes, I was getting the same error.
I did try the with, but I did with selection, not with wks.
Again-- thank you for your helps.
And to Barb, Don, Dave-- thank you all for your helps.
Best to you all........
SteveB.


"RyanH" wrote:

I was getting an error on your strWbkName line. Are you? Give this a try:

Sub A1ReNmWksht()

Dim strWbkName As String
Dim wbk As Workbook
Dim wks As Worksheet
Dim lngLastSheet As Long

' get last 3 characters of the workbook name- minus file extension
strWbkName = Mid(ActiveWorkbook.Name, 5, InStr(ActiveWorkbook.Name, ".")
- 5)

' where you want the data to go
Set wbk = Workbooks("TROABook-200-299.xlsx")
lngLastSheet = wbk.Sheets.Count

' find worksheet name and change worksheet name if found
For Each wks In ActiveWorkbook.Worksheets
Select Case wks.Name
Case "Sum", "Summary", "SUM", "summary"
With wks
.Name = "Sum-" & strWbkName
.Copy After:=wbk.Sheets(lngLastSheet)
End With


Case "APN"
With wks
.Name = "APN-" & strWbkName
.Copy After:=wbk.Sheets(lngLastSheet)
End With

End Select
Next wks

End Sub


--
Cheers,
Ryan


"SteveDB1" wrote:

Yes, the final destination workbook is open.
The entirety of the code is:
------------------------------------------------------------
Sub A1ReNmWksht()

Dim strWbkName As String

Dim wks As Worksheet

' get last 3 characters of the workbook name- minus file extension
strWbkName = Mid(ActiveWorkbook.Name, 5, InStr(ActiveWorkbook.Name, ".")
- 5)


' find worksheet name and change worksheet name if found
For Each wks In ActiveWorkbook.Worksheets
Select Case wks.Name
Case "Sum", "Summary", "SUM", "summary"
wks.Name = "Sum-" & strWbkName
wks.Copy
after:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.count)



Case "APN"
wks.Name = "APN-" & strWbkName
wks.Copy
after:=Worksheets(Workbooks("TROABook-200-299.xlsx").Sheets.count)

End Select

Next wks

End Sub
-------------------------------------------------------------
Again, thank you.



"RyanH" wrote:

Is the Workbooks("TROABook-200-299.xlsx") open? If it is not open you will
get that error.

Can you post the rest of the code? This will help me to diagnose things.
--
Cheers,
Ryan


"SteveDB1" wrote:

Barb, and Ryan,

Thank you both for your responses.
I've tried both and get the same error.
subscript out of range.

For Ryan's, the error occurs with the
wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

.....:= sheets(...) component.

the line shows 23 sheets, within the (Workbooks(...).sheets.count element,
but once it is "outside" with the sheets(....) portion it gives the subscript
out of range error.


For Barb's, the error occurs
Set newWB = Workbooks("TROABook-200-299")
workbooks(...) = <subscript out of range component.
Barb, what if, instead of a new workbook, it just sets the TROABook as being
active?

I copied your forms and pasted each-- to make sure I didn't mis-type anything.

Again-- thank you both.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default copy method failed

I'd include the extension in Barb's code:

Set newWB = Workbooks("TROABook-200-299.xlsx")

RyanH wrote:

Is the Workbooks("TROABook-200-299.xlsx") open? If it is not open you will
get that error.

Can you post the rest of the code? This will help me to diagnose things.
--
Cheers,
Ryan

"SteveDB1" wrote:

Barb, and Ryan,

Thank you both for your responses.
I've tried both and get the same error.
subscript out of range.

For Ryan's, the error occurs with the
wks.Copy After:=Sheets(Workbooks("TROABook-200-299.xlsx").Sheets.Count)

.....:= sheets(...) component.

the line shows 23 sheets, within the (Workbooks(...).sheets.count element,
but once it is "outside" with the sheets(....) portion it gives the subscript
out of range error.


For Barb's, the error occurs
Set newWB = Workbooks("TROABook-200-299")
workbooks(...) = <subscript out of range component.
Barb, what if, instead of a new workbook, it just sets the TROABook as being
active?

I copied your forms and pasted each-- to make sure I didn't mis-type anything.

Again-- thank you both.


--

Dave Peterson
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default copy method failed

I'd use something like this

myws.Copy after:=newWB.Worksheets(newWB.Worksheets.Count)

--
HTH,
Barb Reinhardt



"SteveDB1" wrote:

hi all.
I've modifed an existing macro to copy renamed worksheets in to a secondary
workbook.
I've read the KB file from MS that Jim Thomlinson has posted regarding this
issue, and if I understand it correctly the problem mainly occurs when the
user seeks to copy a worksheet in to the same workbook.
My goal is to copy the worksheet in to another, existing workbook.

wks.Copy after:=Workbooks("TROABook-200-299.xlsx").Sheets.count

the response I get from VBA is a 1004 error, stating that the copy method
failed.

My intention is to copy the renamed worksheets into a different workbook
than they are originally in, and at the end.
What am I doing wrong here...?

Thank you.
Your helps are appreciated.
SteveB.

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
Method 'Copy' of object'_Worksheet failed q2w3e4r Excel Worksheet Functions 1 February 7th 07 01:17 PM
Method 'Copy' of object'_Worksheet failed [email protected] Excel Programming 4 February 6th 07 06:23 PM
Copy method failed Daniel Bonallack Excel Programming 2 October 14th 05 05:24 AM
Copy Method of Worksheet Class Failed Steph[_3_] Excel Programming 1 April 5th 04 09:56 PM
Copy Method of Worksheet Class Failed Steph[_3_] Excel Programming 1 April 5th 04 09:38 PM


All times are GMT +1. The time now is 07:51 AM.

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

About Us

"It's about Microsoft Excel"