Hello,
I want to create a backup excel workbook encrypted with password whenever I hit a button save.
So far I have this but still canīt figure out how to protect all new .xlsm files with password so noone canīt do a change in backup files without knowing a password. Saving and creating backup files in different folder works.
Thanks.
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim DestinationFolder As String
Dim WbName As String
Dim WbExtension As String
Dim WbNewPath As String
Dim sHostName As String
sHostName = Environ$("computername")
DestinationFolder = "C:\Users\An\Dropbox\Orders - backup"
If DestinationFolder = "" Or Dir(DestinationFolder, vbDirectory) = vbNullString Then
MsgBox "The destination folder's path is incorect!", vbCritical, "Wrong folder's path"
Exit Sub
End If
WbName = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1))
WbExtension = Right$(ThisWorkbook.Name, Len(ThisWorkbook.Name) - InStrRev(ThisWorkbook.Name, "."))
WbNewPath = DestinationFolder & "\" & WbName & sHostName & "(" & Format(Now(), "dd.mm.yyyy - hh.mm") & ")." & WbExtension
ThisWorkbook.SaveCopyAs WbNewPath
End Sub
Bookmarks