MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Convert into VBA

  Asked By: Hamish    Date: Sep 07    Category: MS Office    Views: 1590

Can any one please tell me how to i convert this code in VBA
Function PostURL(sURL, aPostData)
sURL = CStr(sURL)
Dim oXml
Set oXml = Server.CreateObject ("Microsoft.XMLHTTP")
oXml.Open "POST", sURL, False
oXml.setRequestHeader "Content-Type","application/ x-www-form- urlencoded"
oXml.Send aPostData
PostURL = oXml.responseText
Set oXml= Nothing
End Function

social = "536-58-8931"
Response.write PostURL("http://ssdi.rootsweb.com/cgi-bin/ssdi.cgi",



3 Answers Found

Answer #1    Answered By: Debbie Reyes     Answered On: Sep 07

This is ASP code. The only major differences are the ASP framework provides
the Server and Response objects, so you don t have them here in VBA.

Server.CreateObject can simply be replaced with just CreateObject (drop the

Response.write is how you display HTML on a web page. In this case it s how
the sample code  shows the results of the web page invocation, so you can
either MsgBox it or Debug.Print it or when you re ready, store the results
wherever you want them to go. For now you may wish to try:

Msgbox PostURL("http://ssdi.rootsweb.com/cgi-bin/ssdi.cgi", "ssn="&social)

and see where you go from there.

Answer #2    Answered By: Leroy Schmidt     Answered On: Sep 07

Set a reference for Microsoft XML.

Dim sURL As String
Dim strResults As String

The rest of your existing code  is rather similar, though I would pass
the variable (SSN) during the initial request, For example...

Set X = New MSXML.XMLHTTPRequest
sURL =
N=0&keywords=" & sSocial
Call X.Open("GET", sURL, True)
X.Send (Null)
strResults = X.responseText

Set X = Nothing

Answer #3    Answered By: Edwin Chavez     Answered On: Sep 07

both DoItWithPOST and DoItWithGET return the desired results.

I did need to change the third parameter on the Open call in Craig's code
(in my DoItWithGET) to False from True to tell it to wait for the response.

Make sure Option Explicit is not set for this code  to work, though it
wouldn't be hard to specify all the types.

I'm not bothering to set a reference to pick up the XMLHTTP objects in my
version of Craig's GET code, just using CreateObject.

Didn't find what you were looking for? Find more on Convert into VBA Or get search suggestion and latest updates.