title: Calling function BeforeClose event in VBA not working
body: <p>I am trying to call a protection function to execute before the workbook closes but it's not working. The protection sub works fine on its own but not when called in WorkBook_BeforeClose()</p>
  
  <p>This is the code found in Module 1:</p>
  
  <pre><code>Public Sub protect()
  
  Dim index As Integer
  index = 1
  
  Do While index &lt;= ActiveWorkbook.Worksheets.Count
  ActiveWorkbook.Sheets(index).Activate
  If ActiveSheet.Name &lt;&gt; "README" Then
      ActiveSheet.unprotect
      Cells.Select
      Selection.Locked = True
      Selection.FormulaHidden = False
      ActiveSheet.protect DrawingObjects:=True, Contents:=True, Scenarios:=True
      ActiveSheet.Range("A1").Select
  End If
  index = index + 1
  Loop
  
  ActiveWorkbook.Sheets(1).Activate
  
  End Sub
  </code></pre>
  
  <p>This is the code found in ThisWorkbook:</p>
  
  <pre><code>Private Sub Workbook_BeforeClose(Cancel As Boolean)
      Call protect
  End Sub
  </code></pre>