title: How to escape infinite loop in VBA / VB.NET
body: <p>bit of a stupid question, but I couldn't find any answers to it.<br>
  Sadly, I made a very shameful error, where I created an endless loop by accident.</p>
  
  <pre><code>Private Sub Textbox1_Change()
      Do While Len(Trim(Textbox1.Text)) &gt; 4
         MsgBox "Please enter your birthyear in format of ####"
      Loop
  End Sub
  </code></pre>
  
  <blockquote>
    <p>As I wanted to enforce users to type only 4 digits, obviously not
    realising I made an <a href="/questions/tagged/infinite-loop" class="post-tag" title="show questions tagged &#39;infinite-loop&#39;" rel="tag">infinite-loop</a> given it's impossible to close
    the <code>MsgBox</code>  as once you reach <code>&gt;4</code> characters, it keeps on creating
    new <code>MsgBox</code>es even after you QueryClose/OK the one that popped up.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/6QwdS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6QwdS.png" alt="enter image description here"></a></p>
  
  <p>Is there a way I could cancel it, without closing Excel altogether? Sadly, I can't even pause the code given the <code>MsgBox</code> opened in modal form and I can't click any of the editor elements.</p>
  
  <p><a href="https://i.stack.imgur.com/EfAI2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EfAI2.png" alt="enter image description here"></a></p>