title: How to enable events so Workbook_BeforeSave gets called
body: <p>My <code>Workbook_BeforeSave</code> event is not called before saving</p>
  
  <p>This is my code:</p>
  
  <pre><code>Option Explicit
  
  Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
     a = MsgBox("Do you really want to save the workbook?", vbYesNo)
     If a = vbNo Then Cancel = True
  End Sub
  </code></pre>
  
  <p>This is probably normal, because events are probably not enabled.
  Now I tried to put <code>Application.Events = True</code> like this:</p>
  
  <pre><code>Option Explicit
  Application.Events = True
  
  Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
     a = MsgBox("Do you really want to save the workbook?", vbYesNo)
     If a = vbNo Then Cancel = True
  End Sub
  </code></pre>
  
  <p>This doesn't change anything, Workbook_BeforeSave is still not called up on saving. But when I close the excel file, following error message is displayed :</p>
  
  <p><img src="https://i.stack.imgur.com/oopM8.png" alt="enter image description here"></p>
  
  <p>The english translation is "Compilation error: Incorrect instruction outside of a procedure."</p>
  
  <p>Apparently the <code>Application.Events = True</code> is not at the right place, but where should I put it ?</p>