title: Close the download window in IE 9 once download completes using Excel vba
body: <p>my code freezes at line DoEvents and does not go further.Here i am trying to close the browser once download completes.Please advice.`</p>
  
  <pre><code>Dim hWnd As LongPtr
  Dim timeout As Date
  Dim fullfilename As String
  Dim AutomationObj As IUIAutomation
  Dim WindowElement As IUIAutomationElement
  
  'Find the Download complete window, waiting a maximum of 1 minutes for it to appear.  Timeout value is
  'dependent on the size of the download, so make it longer for larger files.
  
  timeout = Now + TimeValue("00:01:00")
  
  Do
      hWnd = FindWindow("#32770", "Download complete")
      DoEvents
      Sleep 200
  Loop Until hWnd Or Now &gt; timeout
  
  Debug.Print "   Download complete window "; Hex(hWnd)
  
  If hWnd Then
      oBrowser.Quit
  End If`
  </code></pre>