View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Web Browser Control and Javascript

You need to find the value in the IE.Document object. I usally perform a
dump of the IE object like in the code below and try to find the value in the
innertext. Another method is to search for the TAG or ID using these two
statements

Set Form = IE.document.getElementsByTagname("Form")
Set zip5 = IE.document.getElementById("zip5")

Tags in the HTML start with forward slasshes /Form
ID in html look like id="zip5"

You can view the HTML from the IE web browser by going to View - Source.




Sub GetZipCodes()

ZIPCODE = InputBox("Enter 5 digit zipcode : ")

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://zip4.usps.com/zip4/citytown_zip.jsp"

'get web page
IE.Navigate2 URL
Do While IE.Readystate < 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop
Set Form = IE.document.getElementsByTagname("Form")

Set zip5 = IE.document.getElementById("zip5")
zip5.Value = ZIPCODE

Form(0).submit
Do While IE.busy = True And IE.Readystate < 4
DoEvents
Loop

'----------------------------------------------------------------------
'dump the document to the worksheet
RowCount = 1
For Each itm In IE.document.all
Range("A" & RowCount) = itm.tagname
Range("B" & RowCount) = itm.classname
Range("C" & RowCount) = Left(itm.innertext, 1024)
RowCount = RowCount + 1
Next itm
'---------------------------------------------------------------------------

Set Table = IE.document.getElementsByTagname("Table")
If Table(0).Rows(0).innertext = "" Then
MsgBox ("Invalid Zip code")
Else
Location = Table(0).Rows(2).innertext
End If
IE.Quit
MsgBox ("Zip code = " & ZIPCODE & " City/State = " & Location)


End Sub




"Arry Potter" wrote:

Hi,

I have a Javascript code inside a webpage in a webbrowser control on a
excel sheet. There is some value in the javascript which I wish to pass to
the Excel sheet.How can I do this

Excel sheet - webrowser control
webbrowser control - opened a webpage
webpage has javascript code - run code and returns a result
result from javascript - back to excel sheet cell

Configuration :
WinXP,IE6,Office 2003

Regards,
Arry