简体   繁体   中英

Copy worksheets from 1 workbook to another open workbook

I'm using the below code to move a worksheet from one open workbook to another open workbook but it's breaking on the last line of the code. From everything that I see online, it looks like this code should work.

Error MSG : (Run-time error '9') (Subscription out of range)

Sheets("Summary ML").Select

Workbooks.Open Filename:=outputfile
Windows(wb).Activate
Sheets("Summary ML").Select
Sheets("Summary ML").Copy After:=Workbooks("outputfile.xlsx").Sheets(2)

Maybe you can use this :

Workbooks("Book1.xlsx").Worksheets.Copy Before:=Workbooks("Book2.xlsx").Sheets(1)

If you don't know the meaning of sheet(1) you can do debug.print sheet(1).Name

Kindest regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM