title: How to send files via HTTP_POST with Excel using VBA?
body: <p>The question asked here: <a href="https://stackoverflow.com/questions/158633/how-can-i-send-an-http-post-request-to-a-server-from-excel-using-vba">How can I send an HTTP POST request to a server from Excel using VBA?</a> is almost exactly what I was looking for except that I am trying to send a number of files to the server. I googled further and found <a href="https://stackoverflow.com/questions/3939578/how-do-i-upload-a-zip-file-via-http-post-using-vba">How do I upload a zip file via HTTP post using VBA?</a> This was also good, but pretty discouraging - it seems like a lot of work (not just making an HTML form here...). </p>
  
  <p>Option #2 here: <a href="http://www.motobit.com/tips/detpg_post-binary-data-url/" rel="noreferrer">http://www.motobit.com/tips/detpg_post-binary-data-url/</a> (as cited in the question on SO noted above) seems like it would work well, but as I work in JS and CSS, I have no idea how to create FormData (the binary files to send to the server) in the example. </p>
  
  <p>Can anyone please help me? In essence, I want to send 3-6 files over HTTP_POST via VBA from inside Excel to a PHP script on a web server that is expecting form data such as . An HTML form to handle this would look like:</p>
  
  <pre><code>&lt;form action="upload_file.php" method="post" enctype="multipart/form-data"&gt;
    &lt;input name="userfile[]" type="file" /&gt;&lt;br /&gt;
    &lt;input name="userfile[]" type="file" /&gt;&lt;br /&gt;
    &lt;input name="userfile[]" type="file" /&gt;&lt;br /&gt;
    &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Thank you all in advance.</p>
  
  <p>EDIT -- Aug. 2nd 2012</p>
  
  <p>I'm still trying to work on this issue. I don't know VBA/6, pretty much just basic JS so I am a little lost. Here is what I have done so far: </p>
  
  <pre><code>Sub HTTPInternetPutFile()
  
      ' create new object with WinHttpRequest for this operation
      Dim WinHttpReq As Object
      Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
      Dim FormFields As String
  
      ' initialize variables that we will set and pass as parameters
      Dim sfpath
      Dim strURL As String
      Dim StrFileName As String
  
  
         StrFileName = "CLIPrDL.csv"
         sfpath = "C:\CLIPr\"
         strURL = "http://s0106001c10187ab1.gv.shawcable.net/uploadtest/upload_file.php"
  
  
         WinHttpReq.Open "POST", strURL, False
  
  
         ' Set headers
         WinHttpReq.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
         WinHttpReq.setRequestHeader "Accept-Charset", "ISO-8859-1,utf-8"
         WinHttpReq.setRequestHeader "Content-Type", "multipart/form-data"
         ' WinHttpReq.setRequestHeader "Content-Type", "text/html;charset=UTF8"
         WinHttpReq.setRequestHeader "Content-Disposition", "form-data; name=""userfile[]"""
  
         ' I dont understand this... why use fileup??
         FormFields = """filename=" &amp; StrFileName &amp; """"
         FormFields = FormFields &amp; "&amp;"
         FormFields = FormFields &amp; sfpath
  
         ' so comment it out for now
         ' WinHttpReq.Send FormFields
         WinHttpReq.Send sfpath &amp; StrFileName
  
         ' output this var to a message box becuase I dont know what it does really
         MsgBox FormFields
         ' Display the status code and response headers.
         MsgBox WinHttpReq.GetAllResponseHeaders
         MsgBox WinHttpReq.ResponseText
  
  
  End Sub
  </code></pre>
  
  <p>The message boxes at the bottom of the script do output the server's headers and response (blank HTML page). I feel that there is something that I am not setting in the headers to make the server happy (note: trying commenting out Content-Type). </p>
  
  <p>If anyone out there has experience using the WinHttpRequest object in VBA/6 to POST a binary file via HTTP, please help! :) </p>