Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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

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
copy&paste of several sheets in a folder to a workbook with somesh Ray Excel Programming 2 June 4th 07 03:06 AM
copy all and paste values for all sheets in a workbook cass calculator Excel Worksheet Functions 6 June 1st 07 02:58 PM
copy/paste values for all sheets in workbook cass calculator Excel Programming 2 May 31st 07 11:36 PM
I cannot paste from one workbook to another. Copy works, paste do. JimmyMc Excel Discussion (Misc queries) 1 June 10th 05 03:54 PM
Copy a range of cells in an unopened workbook and paste it to the current workbook topstar Excel Programming 3 June 24th 04 12:50 PM


All times are GMT +1. The time now is 02:56 PM.

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"