ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy and paste sheets between workbook (https://www.excelbanter.com/excel-programming/391857-copy-paste-sheets-between-workbook.html)

anamarie30

Copy and paste sheets between workbook
 
I got "Subscript out of range" error when I used the above code. That I want
is: I got a binder that contain two worksbooks. My first workbook have a
command button. When I press this botton it suppose that the macro open the
second workbooks (until here my code work fine) and copy the sheet
"AssessmentTemplate". Then paste the sheet to the first workbook after it
last sheet. My error is produced in the line that is coding the copy. Thanks
for any help.

stFileName = "AssessmentTemplate.xls"
stPath = ThisWorkbook.Path
stFullName = stPath & "\" & stFileName
Set Wkb = Workbooks.Open(Filename:=stFullName)

Wkb.Sheets("AssessmentTemplate").Select
With Selection
.Copy After:=Workbooks("MacroTemplate").Sheets(2) 'Error message with
line
End With

Dave Peterson

Copy and paste sheets between workbook
 
Sheets("AssessmentTemplate").Copy _
After:=Workbooks("MacroTemplate.xls").Sheets(2)

(I'd include the extension. It's safer.)



anamarie30 wrote:

I got "Subscript out of range" error when I used the above code. That I want
is: I got a binder that contain two worksbooks. My first workbook have a
command button. When I press this botton it suppose that the macro open the
second workbooks (until here my code work fine) and copy the sheet
"AssessmentTemplate". Then paste the sheet to the first workbook after it
last sheet. My error is produced in the line that is coding the copy. Thanks
for any help.

stFileName = "AssessmentTemplate.xls"
stPath = ThisWorkbook.Path
stFullName = stPath & "\" & stFileName
Set Wkb = Workbooks.Open(Filename:=stFullName)

Wkb.Sheets("AssessmentTemplate").Select
With Selection
.Copy After:=Workbooks("MacroTemplate").Sheets(2) 'Error message with
line
End With


--

Dave Peterson

Tom Ogilvy

Copy and paste sheets between workbook
 
stFileName = "AssessmentTemplate.xls"
stPath = ThisWorkbook.Path
stFullName = stPath & "\" & stFileName
Set Wkb = Workbooks.Open(Filename:=stFullName)

Wkb.Sheets("AssessmentTemplate").Select
With ActiveSheet '<== change to reflect sheet, not range
.Copy After:=Workbooks("MacroTemplate.xls").Sheets(2) '<= add .xls
End With

--
Regards,
Tom Ogilvy

"anamarie30" wrote:

I got "Subscript out of range" error when I used the above code. That I want
is: I got a binder that contain two worksbooks. My first workbook have a
command button. When I press this botton it suppose that the macro open the
second workbooks (until here my code work fine) and copy the sheet
"AssessmentTemplate". Then paste the sheet to the first workbook after it
last sheet. My error is produced in the line that is coding the copy. Thanks
for any help.

stFileName = "AssessmentTemplate.xls"
stPath = ThisWorkbook.Path
stFullName = stPath & "\" & stFileName
Set Wkb = Workbooks.Open(Filename:=stFullName)

Wkb.Sheets("AssessmentTemplate").Select
With Selection
.Copy After:=Workbooks("MacroTemplate").Sheets(2) 'Error message with
line
End With



All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com