title: VBA Code in Workbook_BeforeClose runs but has no effect
body: <p>I have the following code in an Excel 2010 workbook:</p>
  
  <pre><code>Private Sub Workbook_BeforeClose(Cancel As Boolean)
  
      Dim FileName As String
  
      FileName = ActiveWorkbook.Name
  
      If FileName = "False" Then Exit Sub
  
      If FileName &lt;&gt; "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
  </code></pre>
  
  <p>The code executes if I insert a breakpoint and run it line-by-line, but when I reopen the workbook it does not prompt for the "abc123" password to open not in Read Only mode - it just opens. What am I doing wrong? I made sure macros are enabled.</p>