Hi All
I am using the below code in the workbook before close function to open the backup file and paste data from the current workbook so that it doesn't get lost. It's openning the file fine, it's clearing what is currently in there fine, but the paste function is not working.
It seemed to be before today, but now just leaves me with an empty backup sheet - has anyone any ideas why it might not be working?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "Before closing, the system will back-up the payee data to ensure no future loss of information. Please select OK to continue"
Workbooks.Open FileName:=ThisWorkbook.Path & "\Payee Backup\Backup.xlsx"
Dim wkbTo As Workbook
Dim wbkFrom As Workbook
Set wbkTo = ThisWorkbook
Set wbkFrom = ActiveWorkbook
wbkTo.Activate
Sheets("Payment Capture").Visible = True
wbkFrom.Activate
Range("a1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
wbkTo.Activate
Sheets("Payment Capture").Select
Range("a1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
wbkFrom.Activate
Range("A1").Select
ActiveSheet.Paste
wbkTo.Activate
Sheets("Payment Capture").Visible = False
Sheets("PARF System").Select
wbkFrom.Save
wbkFrom.Close
wbkTo.Save
wbkTo.Close
End Sub
Bookmarks