title: VBA - Go to website and download file from save prompt
body: <p>I've been spending the last few hours trying to figure out how to save a file onto the computer using VBA. The code template below that I found on another forum seems promising, except when I go to the desktop to access it, the .csv file has what looks like the page's source code instead of the actual file I want. This may be because when I go to the URL, it doesn't automatically download the file; rather, I am asked to save the file to a certain location (since I don't know the path name of the uploaded file on the site).
  Is there any way to alter this code to accommodate this, or will I have to use a different code entirely?</p>
  
  <pre><code>Sub Test()
  Dim FileNum As Long
  Dim FileData() As Byte
  Dim MyFile As String
  Dim WHTTP As Object
  
  On Error Resume Next
      Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
      If Err.Number &lt;&gt; 0 Then
          Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
      End If
  On Error GoTo 0
  
  
  MyFile = "MY_URL_HERE"
  
  WHTTP.Open "GET", MyFile, False
  WHTTP.send
  FileData = WHTTP.responseBody
  Set WHTTP = Nothing
  
  If Dir("C:\Users\BLAHBLAH\Desktop", vbDirectory) = Empty Then MkDir "C:\Users\BLAHBLAH\Desktop"
  
  FileNum = FreeFile
  Open "C:\Users\BLAHBLAH\Desktop\memberdatabase.csv" For Binary Access Write As #FileNum
      Put #FileNum, 1, FileData
  Close #FileNum
  
  End Sub
  </code></pre>
  
  <p>Cross posts:<br>
  <a href="http://www.ozgrid.com/forum/showthread.php?t=178884" rel="nofollow">http://www.ozgrid.com/forum/showthread.php?t=178884</a><br>
  <a href="http://www.excelforum.com/excel-programming-vba-macros/925352-vba-go-to-website-and-download-file-from-save-prompt.html" rel="nofollow">http://www.excelforum.com/excel-programming-vba-macros/925352-vba-go-to-website-and-download-file-from-save-prompt.html</a></p>