title: Delete a Worksheet upon Exit (if it exists) VBA
body: <p>I am attempting to delete a worksheet from this Excel file upon exit (if it exists). The code I have tells it to automatically delete the sheet and say "yes, delete" in the popup box, but it is not running for some reason. </p>
  
  <pre><code>Private Sub Workbook_BeforeClose(Cancel As Boolean)
  '
  ' This procedure will delete sheet upon exit and select "Yes, Delete" in the 
  '  pop-up box
  '    
  Dim ws As Worksheet
  For Each ws In ActiveWorkbook.Worksheets
      If ws.Name = "Temp" Then
          Application.DisplayAlerts = False
          Worksheets("Temp").Delete
          Application.DisplayAlerts = True
      End If
  Next
  End Sub
  </code></pre>