Dear forum! I'm new to VBA but and this is my first post here
What I'm trying to do is to copy a sheet from a closed workbook to my active workbook.
When I run the macro I receive an error message (run-time error '-2147221080 (800401a8)'), however it works the second time.
The "error line" when debugging is:
When formulation my code I got expired from:
However, instead of using "ThisWorkbook", I'm trying to use active workbook instead since the vba code is in another workbook.
Thanks in advance for any help
Sub Copy sheet from closed workbook() Application.ScreenUpdating = False Dim y As Workbook Set y = ActiveWorkbook Set closedBook = Workbooks.Open("C:\XXXX\XXXX\XXXX.xlsx") closedBook.Sheets("Sheet1").Copy y.Sheets(1) closedBook.Close SaveChanges:=False Application.ScreenUpdating = True End Sub