title: Why does Showing a UserForm as Modal Stop Code Execution?
body: <p>The following VBA code stops at <code>Me.Show</code>. From my tests, it seems that <code>Me.Show</code> stops all code execution, even if the code is inside the UserForm.</p>
  
  <p><em>This part is outside the UserForm</em>:</p>
  
  <pre><code>Public Sub TestProgress()  
      Dim objProgress As New UserForm1
      objProgress.ShowProgress
      Unload objProgress
  End Sub
  </code></pre>
  
  <p><em>This part is inside the UserForm</em>:</p>
  
  <pre><code>Private Sub ShowProgress()
      Me.Show vbModal
      Dim intSecond As Integer
      For intSecond = 1 To 5
          Application.Wait Now + TimeValue("0:00:01")
          Me.ProgressBar1.Value = intSecond / 5 * 100
      Next intSecond
      Me.Hide
  End Sub
  </code></pre>
  
  <p>The code stops at <code>Me.Show</code>, after the UserForm is displayed. There is no error, it just discontinues executing code. It seems that the only way to execute code inside a modal UserForm in VBA is to include it in the UserForm_Activate procedure like this:</p>
  
  <p><em>This part is outside the UserForm</em>:</p>
  
  <pre><code>Public Sub TestProgress()  
      Dim objProgress As New UserForm1
      Load objProgress
      Unload objProgress
  End Sub
  </code></pre>
  
  <p><em>This part is inside the UserForm</em>:</p>
  
  <pre><code>Private Sub UserForm_Initialize()
      Me.Show vbModal
  End Sub
  
  Private Sub UserForm_Activate()
      Dim intSecond As Integer
      For intSecond = 1 To 5
          Application.Wait Now + TimeValue("0:00:01")
          Me.ProgressBar1.Value = intSecond / 5 * 100
      Next intSecond
      Me.Hide
  End Sub
  </code></pre>
  
  <p>Of course, I can't put <code>Me.Show</code> inside UserForm_Activate because that procedure only fires after the UserForm Show event.</p>
  
  <p>The documentation for <code>UserForm.ShowModal</code> says "<em>When a UserForm is modal, the user must supply information or close the UserForm before using any other part of the application. No subsequent code is executed until the UserForm is hidden or unloaded.</em>"</p>
  
  <p>I am trying to use a modal UseForm as a progress bar to prevent the user from interacting with the application while a process runs. But this will be difficult to accomplish if all my code has to be within the UserForm_Activate procedure.</p>
  
  <p>Am I missing something here? Why does all code execution stop at <code>Me.Show</code>?</p>