I have the following code in an Excel 2010 workbook:
The code executes - I checked by inserting a breakpoint and stepping through it. But the password protection to open the file as Read Only unless the password is entered is not being applied - the file just opens as normal. What am I doing wrong?
Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.EnableEvents = True Dim FileName As String FileName = ActiveWorkbook.Name If FileName = "False" Then Exit Sub If FileName <> "Shipping Manifest SaveAS Update.xlsm" Then Application.DisplayAlerts = False ActiveWorkbook.SaveAs FileName:=FileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, WriteResPassword:="abc123", ReadOnlyRecommended:=True Application.DisplayAlerts = True End If End Sub