Copying a worksheet from a closed workbook to the active one

samc2696

New Member
Joined
Jul 16, 2018
Messages
42
Hi all,

I want to copy a sheet from a workbook I have saved to the one I am currently working on. I need this code to be able to do this in any workbook I am working on.

The code so far is as such:
VBA Code:
Dim sourceBook As Workbook
    Application.ScreenUpdating = False
    Set sourceBook = Workbooks.Open("filepath")
    sourceBook.Sheets("Summary").Copy Before:=ThisWorkbook.Sheets(1)
    sourceBook.Close
    Application.ScreenUpdating = True

I have my file's path where it says so above, and I want to copy the worksheet called 'Summary' and paste it before the sheet in the active workbook.

I keep getting a run-time error 1004 - Copy method of Worksheet class failed

Thank you for the help
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
VBA Code:
    sourceBook.Sheets("Summary").Copy Before:=ActiveWorkbook.Sheets(1)
 
Upvote 0
How about
VBA Code:
Dim sourceBook As Workbook, MyBook As Workbook
   Set MyBook = ActiveWorkbook
   Application.ScreenUpdating = False
   Set sourceBook = Workbooks.Open("filepath")
   sourceBook.Sheets("Summary").Copy Before:=MyBook.Sheets(1)
   sourceBook.Close
   Application.ScreenUpdating = True
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top