I have three lines of code that do the following:
(1) Opens another file based on a filepath in a cell in the current workbook.
(2) Copies the values of a named range in the newly opened book.
(3) Pastes values in tab "Detail" of the original workbook.
When I put the three lines in the immediate window, I get an error message "PasteSpecial method of Range class failed", run-time 1004. However, if in the immediate window, I put my mouse at the end of the second line and execute, then put my mouse at the end of the third line and execute it work fine. The error comes if I only try to execute at the end of the third line.
I have tried activating the original workbook where the data is to be pasted (inserting the activate code b/t lines 2 and 3 below), but that didn't change anything. Can anyone tell me what else I need to do so the code can run will work (run all at once)?
(1) Opens another file based on a filepath in a cell in the current workbook.
(2) Copies the values of a named range in the newly opened book.
(3) Pastes values in tab "Detail" of the original workbook.
When I put the three lines in the immediate window, I get an error message "PasteSpecial method of Range class failed", run-time 1004. However, if in the immediate window, I put my mouse at the end of the second line and execute, then put my mouse at the end of the third line and execute it work fine. The error comes if I only try to execute at the end of the third line.
I have tried activating the original workbook where the data is to be pasted (inserting the activate code b/t lines 2 and 3 below), but that didn't change anything. Can anyone tell me what else I need to do so the code can run will work (run all at once)?
Code:
Application.Workbooks.Open Filename:=Range("TEST_FILEPATH"), Password:=("yobaby3")
Worksheets("DETAIL").Range("RANGE_DETAIL").Copy
Workbooks("Rebuild 7 detail").Worksheets("Detail").Range("a1").PasteSpecial Paste:=xlPasteValues