Hi,
I have a routine that copies a range from one file to another. Both sheets are protected and the below code works fine when I run it the first time but gives an error the second time. If I save the files and open them again then run the same code it works correctly. Any help appreciated.
wbSource.Activate
ActiveWorkbook.Worksheets("Inputs").Visible = xlSheetVisible
ActiveWorkbook.Worksheets("Inputs").Select
ActiveWorkbook.Sheets("Inputs").Range("D20:DS307").Select
Selection.copy
ActiveWorkbook.Sheets("Inputs").Range("D20").Select
wbTarget.Activate
ActiveWorkbook.Worksheets("Inputs").Visible = xlSheetVisible
ActiveWorkbook.Worksheets("Inputs").Select
ActiveSheet.Unprotect Password:="Added_password_here"
ActiveWorkbook.Sheets("Inputs").Range("D20").Select
ActiveSheet.Paste
Error that is returned is: Run-time error '1004' Paste method of worksheet class failed
It seems to me that the clipboard is lost (i.e. the 'dotted lines' indicating the selected range on the source sheet) is "lost" when the target sheet is unprotected the second time the code run for some reason.
Any suggestions will be greatly appreciated.
Pete
I have a routine that copies a range from one file to another. Both sheets are protected and the below code works fine when I run it the first time but gives an error the second time. If I save the files and open them again then run the same code it works correctly. Any help appreciated.
wbSource.Activate
ActiveWorkbook.Worksheets("Inputs").Visible = xlSheetVisible
ActiveWorkbook.Worksheets("Inputs").Select
ActiveWorkbook.Sheets("Inputs").Range("D20:DS307").Select
Selection.copy
ActiveWorkbook.Sheets("Inputs").Range("D20").Select
wbTarget.Activate
ActiveWorkbook.Worksheets("Inputs").Visible = xlSheetVisible
ActiveWorkbook.Worksheets("Inputs").Select
ActiveSheet.Unprotect Password:="Added_password_here"
ActiveWorkbook.Sheets("Inputs").Range("D20").Select
ActiveSheet.Paste
Error that is returned is: Run-time error '1004' Paste method of worksheet class failed
It seems to me that the clipboard is lost (i.e. the 'dotted lines' indicating the selected range on the source sheet) is "lost" when the target sheet is unprotected the second time the code run for some reason.
Any suggestions will be greatly appreciated.
Pete