title: How to initiate addin code on .BeforeClose() event
body: <p>I am trying to build my first excel addin that would initiate a code on close of the workbook once certain condition is met. The condition is checked by the on error go to end.</p>
  
  <p>When I run my addin, it looks like this entire part of code does not get initiated.</p>
  
  <p>This code is currently stored in the ThisWorkbook of the add-in.</p>
  
  <pre><code>Private WithEvents App As Application
  
  Private Sub Workbook_Open()
      Set App = Application
  End Sub
  
  Private Sub App_BeforeClose(Cancel As Boolean)
      Dim wb1 As Workbook
      Dim lastrow As Integer
  
      On Error GoTo ENDING
      Application.ScreenUpdating = False
      Workbooks.Open (ActiveWorkbook.Sheets("ADDIN-
  
  DONOTTOUCH").Cells(1.1).Value)
      Set wb1 = ActiveWorkbook
      Set ws = wb1.ActiveSheet
      lastrow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
  
  .....'Other code....
  
  wb1.Save
  wb1.Close
  
  Application.DisplayAlerts = False
  ActiveWorkbook.Sheets("ADDIN-DONOTTOUCH").Delete
  Application.DisplayAlerts = True
  
  Application.ScreenUpdating = True
  ENDING:
  End Sub
  </code></pre>