title: Excel VBA force shutdown IE
body: <p>I am currently using the following sub to close my IE after automating:</p>
  
  <pre><code>Public Sub CloseIE()
      Dim Shell As Object
      Dim IE As Object
  
      Set Shell = CreateObject("Shell.Application")
  
      For Each IE In Shell.Windows
          If TypeName(IE.Document) = "HTMLDocument" Then
              IE.Quit
          End If
      Next
  End Sub
  </code></pre>
  
  <p>This works great but the problem occurs when I try to run the IE code again, I get the following:</p>
  
  <p>Run-time error '-2147023706 (800704a6)':</p>
  
  <p>Automation error</p>
  
  <p>A system shutdown has already been scheduled.</p>
  
  <p>After 20 secs, I can re-run the code. Is there any way of "force closing" IE so that I can run the code again directly after without the error?</p>
  
  <p>EDIT:</p>
  
  <p>Heres the code that initiates IE:</p>
  
  <pre><code>Sub testSub()
  
      Dim IE As Object, Doc As Object, strCode As String
  
      Set IE = CreateObject("internetexplorer.application")
      IE.Visible = True
  
        IE.Navigate "website name"
  
          Do While IE.ReadyState &lt;&gt; 4: DoEvents: Loop
  
          Set Doc = CreateObject("htmlfile")
          Set Doc = IE.Document 
  
         CODE HERE
  
         CloseIE
  
  End Sub
  </code></pre>