Run-Time Error 1004: Copy Method of Worksheet Class Failed

Masoud00

New Member
Joined
Apr 29, 2021
Messages
11
Office Version
  1. 2019
Platform
  1. Windows
Good afternoon,

Background: I have very entry-level VBA knowledge. Trying to create a macro to copy and paste sheets from a closed workbook to current open and active workbooks. Have macro saved to the personal.xlsb to be able to copy paste sheets from that master workbook to unqiue workbooks I work on throughout the day...would like the masterworkbook to stay closed and hidden and not manipulated throughout the process. My understanding is the designation of ThisWorkbook leads the macro to work on personal.xlsb rather than my open file. How can I correct this?

1669224665509.png
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi Masoud00,

your personal workbook is hidden. Set an object to the active workbook and replace ThisWorbook with the variable

VBA Code:
Dim wbAct as Workbook
Set wbAct = activeworkbook

'...
closedBook.Sheets("MedRec").Copy Before:=wbAct.Sheets(1)
'...

Ciao,
Holger
 
Upvote 0
Solution
Hi Masoud00,

your personal workbook is hidden. Set an object to the active workbook and replace ThisWorbook with the variable

VBA Code:
Dim wbAct as Workbook
Set wbAct = activeworkbook

'...
closedBook.Sheets("MedRec").Copy Before:=wbAct.Sheets(1)
'...

Ciao,
Holger
Thank you for your assistance! Works as intended !
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

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