Word/Excel HTTP POST
Tuesday, July 28, 2009 at 02:32PM
Wayne Robinson

A little essoteric, but I recently needed to post some merge fields on a Word application form to a server to save on rekeying when the application form is completed.

Thankfully, VBA in Word can utilise any of the built-in Windows libraries and therefore the above can be easily accomplished using the MSXML2 library.

Some sample code for posting data to a HTTP server in VBA:

Private Sub PostData()

Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.Open "POST", "http://mycompany.com/url/path", False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send "field1=a&field2=b"

MsgBox http.responseText

End Sub

 

Article originally appeared on Wayne Robinson's Blog (http://wayne-robinson.com/).
See website for complete article licensing information.