title: VBA Excel-How to work with cancel button in the MS Excel close?
body: <p>I am running a macro while in <code>Private Sub Workbook_BeforeClose(Cancel As Boolean)</code>
  but whenever user clicks on <strong>Cancel</strong> button macro should not run.</p>
  
  <hr>
  
  <p>I kept following lines of code</p>
  
  <pre><code>Private Sub Workbook_BeforeClose(Cancel As Boolean)
  If Cancel = True Then
      MsgBox "You clicked on Cancel"
  ElseIf Cancel = False Then
      Call SDA
  End If
  </code></pre>
  
  <p>End Sub<br>But whenever i press <strong>Cancel</strong> button it is not showing me any MessageBox.Any help would be appreciated greatly.<img src="https://i.stack.imgur.com/UACPJ.png" alt="enter image description here"></p>