Tuesday, September 28, 2010

Sending a HTTP Request with VBA




a. Sending a HTTP Post Request


Dim result As String
Dim myURL As String, postData As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

myURL = "http://192.168.10.101:80/your_web_service"
postData = "parameter=hello¶meter2=hi"

winHttpReq.Open "POST", myURL, False
winHttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
winHttpReq.Send (postData)

result = winHttpReq.responseText






b. Sending a HTTP Get Request


Dim result As String
Dim myURL As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

myURL = "http://192.168.10.101:80/your_web_service?parameter=hello¶meter2=hi"

winHttpReq.Open "GET", myURL, False
winHttpReq.Send

result = winHttpReq.responseText

Concurrently running Excel VBA/Macro?

Short Answer : IT IS NOT POSSIBLE in Excel 2003 and 2007.

Excel runs built-in functions (e.g. SUM, AVERAGE) concurrently when possible,
but Excel does not run user-defined custom VBA/Macro concurrently.