I have a problem with save a copy of my workbook that i wrote some code to save back up when closing UserForm but don’t work
It works while the workbook is visible or when i click save button
This is the code on workbook before save
Privat sub Workbook_BeforeSave(byvale SaveAsUI as Boolean, Cancel as Boolean)
If MsgBox "some text to inform the user" then
Save_Backup
End if
End sub
Here Save_Backup
Public sub Save_Backup()
Dim FileName as String
Dim WbSource as Workbook
Dim Backup_Folder_Path As String
On error resume next
MkDir thisWorkbook.path & "BackUp"
Backup_Folder_Path = thisWorkbook.path & "BackUp"
On error GoTo 0
Set WbSource = thisWorkbook
FileName = replace(WbSource.Name, "." ,format(Now(), "ddmmyyyy_hhmmss AM/PM."))
WbSource.save
WbSource.Activate
ActiveWorkbook.SaveCopyAs FileName:= Backup_Folder_Path & "" & FileName
Set WbSource = Nothing
End Sub
Please help me
When check the Backup folder no files there
But after closing userForm and the application is visible, when i save the workbook the backup is done and i can see in the Backup Folder