Forum Discussion
Have macro run to protect file with encrypted password
mtarler Thank you. This runs neatly. But what I needed is not protection of the workbook by utilizing the Review-Protect Workbook function, but rather the function that is available with File-Info-Protect Workbook-Encrypt with Password.
The protection via Review-Protect Workbook, can usually quite easily be bypassed or the password hacked.
Could your macro be changed to have the function be: File-Info-Protect Workbook-Encrypt with Password?
egillhelga so this appears to be the same as the Save As option except with the Save As option you can select a PW for open (encryption) and a different PW for edit. Here is that previous code with both Save As passwords added (and I changed from ActiveWorkbook to ThisWorkbook as that is probably better practice):
Private Sub Workbook_Open()
Dim ws As Worksheet
If Now() > DateSerial(2020, 1, 31) Then
ThisWorkbook.Unprotect "password123"
ThisWorkbook.Protect "password123"
For Each ws In ThisWorkbook.Sheets
ws.Protect "password123"
Next
End If
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Password:="password123", writeResPassword:="password-to-modify"
Application.DisplayAlerts = True
End Sub
Obviously you should change these passwords, but when you open the workbook you will need the first password (password123) and then it will prompt you if you want to open as read only or to enter the password to make changes (password-to-modify).