# linking VBA and HTML forms



## indigofire79 (Nov 10, 2004)

Hi all,

I need to create a VBA program that will read a table of names in Excel, search an html form and return values telling if those names exist. How do i link from VBA to the form and read back the data in a VBA friendly manner.

any questions just ask if i am not clear above.

* the form is on www.tuftslife.com: the name directory

Thanks in advance


----------



## CraigCKlein (May 28, 2004)

Well to return the data from a web page use the following:

Create a reference to the Microsoft WinHTTP Service

Then use the following code

Public Sub Command1_Click()
Dim HttpReq As Object
Dim strHTML as String
' Create the WinHTTPRequest ActiveX Object.
Set HttpReq = New WinHttpRequest
' Open an HTTP connection.
HttpReq.Open "GET", "http://www.tuftslife.com", False
HttpReq.Send
strHTML = HttpReq.ResponseText
Debug.Print strHTML​End Sub

Hope this helps.
Craig


----------



## indigofire79 (Nov 10, 2004)

how would i go about doing this: 
_Create a reference to the Microsoft WinHTTP Service??_

also to be more specific, the form is a POST form and i need to query with the following format:

_http://whitepages.tufts.edu/searchresults.cgi METHOD=POST
<input name="search" type="text" id="search"_

i will read in the names from the worksheet into a string variable.
How do i query the form?

thanks for all your help so far

indigofire79


----------



## CraigCKlein (May 28, 2004)

To Create a Reference go to the Module window of the application you are using Select Tools/References and in this list you will see the Microsoft WinHTTP Service.

If the Post method is done via a constant string you will use that in your get statement. 

You will not be "querying" the form, you will be doing a string search using the HTML and the value in excel. e.g. If instr(1, strHTML, strExcel) > 0 Then ITEMFOUND=True.


I never said this would be easy did I?


----------



## indigofire79 (Nov 10, 2004)

This is great.... but

I still need to give the data to the HTML form so it can return some results

*please help me *

_here is some of what i have so far:

'Gets names from sheet and reads them into name array
Sub GetFromSheet()

Dim row, col As Integer

Range("A1").Select
For row = 1 To Length
For col = 1 To Width
names(row, col) = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
Next col
ActiveCell.Offset(1, -Width).Select
Next row
End Sub

Sub GetFromWebForm()

Dim HttpReq As Object
Dim strHTML As String
' Create the WinHTTPRequest ActiveX Object.
Set HttpReq = New WinHttpRequest
' Open an HTTP connection.
HttpReq.Open "POST", "http://whitepages.tufts.edu/searchresults.cgi", False
HttpReq.Send
strHTML = HttpReq.ResponseText
Debug.Print strHTML
MsgBox (strHTML)

Call CreateAfile(strHTML)

End Sub

_

Thanks,

Alex


----------

