title: Application.Quit in UserForm attempts to run rest of macro before exiting
body: <p>My question is: using VBA in Excel 2013 how can I gracefully close an entire instance of Excel when the user decides they don't want to fill out a UserForm and clicks quit or cancel?  </p>
  
  <p>Currently, if the user clicks quit or cancel, I check to see if my instance is the only one open.  If it is not, I can use ThisWorkbook.Close and I think I will be okay.  However, if it is, I do not want the application to still be present, so I used Application.Quit.  This, though, tries to finish running the macro, throws errors (originally "type mismatch" because I unload the form), and only closes after I click "Debug" or "End" (which it does so fast for either I cannot actually debug).  I'm ignoring the first case for now and just trying to exit the entire application.  It's a very long macro with a lot of subroutines and functions, so for debugging and posting here, I have shortened it.  The type mismatch error no longer occurs, but I believe that was a consequence of the actual error: code running after the command to close the application is called.  </p>
  
  <p>First, here's the code that starts everything:</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  
      Call form_variables
      frm_REQUEST.Show
      Call a_REQUEST_main
  
  End Sub
  </code></pre>
  
  <p>The subroutine</p>
  
  <pre><code>form_variables
  </code></pre>
  
  <p>is a subroutine that creates public variables so I can store the data from the UserForm.</p>
  
  <pre><code>frm_REQUEST.Show
  </code></pre>
  
  <p>initializes (including calling a function that finds another workbook, extracts a list, does some formatting, closes the workbook and enters the list into the userforms drop down box) and shows the form, and finally</p>
  
  <pre><code>a_REQUEST_main
  </code></pre>
  
  <p>uses the public variables (where UserForm data is stored) and does its thing (but shouldn't do anything if the UserForm is closed).</p>
  
  <p>The code that is executed when .Show is called is:</p>
  
  <pre><code>Private Sub UserForm_Initialize()
  
      ' Get job numbers from other workbook
      Dim job_selection_list As Variant
      job_selection_list = get_job_list()
  
      With frm_REQUEST.Job_Number_ComboBox
          .List = job_selection_list
      End With
  
      ' set focus on Job Numbers
      JN_combobox.SetFocus
  
  End Sub
  
  Private Sub cancel_button_Click()
  
      Set job_selection_list = Nothing
  
      Unload Me
  
      Application.Quit
  
  End Sub
  
  
  Private Sub submit_button_Click()
  
      ' Values from userform saved as global (?) variables so other subroutines can access.
  
  End Sub
  </code></pre>
  
  <p>I stepped through the program and saw that, once Application.Quit is called in the UserForm, the macro, in the main subroutine, steps to </p>
  
  <pre><code>Call a_REQUEST_main
  </code></pre>
  
  <p>but it should really just close everything out.  I tried doing "save" commands, and changing the order of things, and read about objects needing to be set to nothing (hence the setting of the job_selection_list which is created when the drop down list is initialized), but I cannot seem to get this to work, or find anything online. Can anyone provide some guidance or let me know of a better way to close an excel instance?  Help me Stack-Overflow Kenobi, you're my only hope!</p>
  
  <p>Thanks.</p>