title: Alternative to URLDownloadtofile when automating IE with VBA
body: <p>I have been using InternetExplorer.application with Excel VBA for quite a while with few issues.  One problem I have is downloading a file from website.  I can get as far as having the "Open/Save As" buttons appear but that is where I am stuck. </p>
  
  <p>I've tried using URLDownloadToFile and it does not seem to work through the same session as the InternetExplorer.application objects that I have.  It usually returns the HTML text for a webpage stating that authentication is required.  If I have multiple browsers open and some of the old ones are already authenticated then it will download the file most of the time.</p>
  
  <p>Is there a way to download the file using the InternetExplorer.application object itself?  If not, is there some way I can associate the URLDownloadtofile function with the object that is already authenticated and logged into the website? </p>
  
  <p>EDIT: </p>
  
  <p>The code I've been using is: </p>
  
  <pre><code>    IE2.navigate ("https://...")
      strURL = "https://..."
      strPath = "c:\..."
      Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)
  </code></pre>
  
  <p>I've also tried: </p>
  
  <pre><code>    Do While IE2.Readystate &lt;&gt; 4
          DoEvents
      Loop
      SendKeys "%S"
      IE2.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT
  </code></pre>
  
  <p>And: </p>
  
  <pre><code>    Dim Report As Variant
      Report = Application.GetSaveAsFilename("c:\...", "Excel Files (*.xls), *.xls")
  </code></pre>
  
  <p>No success in any of these, except for the first one which sometimes saves the actual file, but sometimes saves the website that states the authentication error.</p>
  
  <p>Thanks,</p>
  
  <p>Dave</p>