title: VBA code to wait until file download from IE is complete
body: <p>I'm trying to download an excel file from a webpage and so far I was able to open the webpage, navigate and click on save button but I need to access that excel file once it is downloaded. But sometimes it takes time to download depending on the size of the file. Is there any way we can check the window and see if the download is complete and only then to proceed to open the downloaded file. Below is the code.</p>
  
  <pre><code>Dim o As IUIAutomation
  Dim e As IUIAutomationElement
  Set o = New CUIAutomation
  h = IE.hwnd
  
  h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
  
  If h = 0 Then
  
      MsgBox "Not Found"
  
  End If
  
  
  Set e = o.ElementFromHandle(ByVal h)
  Dim iCnd As IUIAutomationCondition
  Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")
  
  Dim Button As IUIAutomationElement
  Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
  Dim InvokePattern As IUIAutomationInvokePattern
  Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
  InvokePattern.Invoke
  </code></pre>
  
  <p>The above code will save the download file</p>