title: VBA: Exiting a macro during runtime via userform button results in error 429 when restarting the macro
body: <p>I have macro in Excel which extracts data from two other workbooks and imports it. During this process, a progress bar is shown and the user can quit at any time via a cancel and the standard X button.</p>
  
  <p>When I quit the process using any of these two buttons, it gives me the error 429 when I try to start the macro again. Somehow my form is still active I guess. After I press the reset button in the VBA editor, I can start the macro again without any errors.</p>
  
  <p>I also have an OK button on my form which becomes active when the import process is completely finished.</p>
  
  <p>All of these three buttons execute the same code snippet which is closing everything. The only difference is that they are used at different points of the execution which makes it a little confusing to debug.</p>
  
  <p>My progress bar:</p>
  
  <p><a href="https://i.stack.imgur.com/Ptjim.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ptjim.png" alt="progress bar"></a></p>
  
  <p>Code in userform:</p>
  
  <pre><code>Dim Button As String
  Sub StartForm(CalledFrom As String)
  
      Button = CalledFrom
  
  End Sub
  
  Private Sub UserForm_Initialize()
  
      ProgressBar.PBOKButton.Enabled = False
  
  End Sub
  
  Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  
      If CloseMode = 0 Then
  
          If ProgressBar.PBBar.Width &lt; 200 Then
  
              If MsgBox("Wollen Sie den Vorgang wirklich abbrechen?", vbYesNo + vbQuestion, "Extrahiere Daten...") = vbNo Then
  
                  'Do nothing
                  Cancel = True
  
              Else
  
                  ExitProcess
  
              End If
  
          Else
  
              ExitProcess
  
          End If
  
      End If
  
  End Sub
  
  Private Sub UserForm_Activate()
  
      If Button = "GetDataButton" Then
  
          GetData
  
      End If
  
  End Sub
  
  Private Sub PBOKButton_Click()
  
      ExitProcess
  
  End Sub
  
  Private Sub PBCancelButton_Click()
  
      If MsgBox("Wollen Sie den Vorgang wirklich abbrechen?", vbYesNo + vbQuestion, "Extrahiere Daten...") = vbYes Then
  
          ExitProcess
  
      End If
  
  End Sub
  </code></pre>
  
  <p>Code snippet to end it all (stored in my macro)</p>
  
  <pre><code>Sub ExitProcess()
  
      KostenstellenWB.Close SaveChanges:=False
  
      MAStundenWB.Close SaveChanges:=False
  
      ExcelApp.Quit
  
      Set ExcelApp = Nothing
  
      End
  
  End Sub
  </code></pre>
  
  <p>Error</p>
  
  <p><a href="https://i.stack.imgur.com/REu4Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/REu4Q.png" alt="error"></a></p>
  
  <p>Thanks for any help.</p>