Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Web Browser Control and Javascript

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Web Browser Control and Javascript

Can you post a small representative example of the javascript code ?

Tim

"Arry Potter" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Web Browser Control and Javascript

Dear All,
I have found the solution.Here is a detailed explanaition

Problem : Call VBA routine from Javascript or Pass data from Webpage to
Excel Sheet or passing data from javascript to web browser control

Solution:
To do this add a webbrowser control in excel
OPen the website from which you want to pass the data to the excel
Ask the javascript on this custom page to pass values to the STATUS BAR
From the status bar you can pick it using webbrowser_1 text changed()

Here is an example - sorry cant post the original due to copyright issues

<html
<body
<script type="text/javascript"
var a;
a = 10 ;
window.status = a;
</script
</body
</html

Here the javascript is returning value 10 . I pass this value to the status
bar

In excel I write the following -
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
If Text < "" Then
RowCount = 1
If Text < "done" Then
Range("A" & RowCount) = Text

End If


End If
End Sub

I first check if there is any text changing in status bar once I realize
that text has changed. I caputre the changed text to a row in excel.

Hope this helps others in need

Regards
Arvind
"Tim Williams" wrote:

Can you post a small representative example of the javascript code ?

Tim

"Arry Potter" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Browser Control - Fit Image to Window Dan Hatola Excel Programming 2 February 5th 09 12:05 AM
Web Browser Control for Animation. ExcelMonkey Excel Programming 1 August 24th 05 01:22 PM
Web Browser Control won't refresh Dee Veloper[_2_] Excel Programming 0 January 18th 05 01:56 PM
WEB Browser Control JT[_2_] Excel Programming 5 September 8th 04 08:36 PM
Web Browser Control JT[_2_] Excel Programming 1 September 3rd 04 10:01 PM


All times are GMT +1. The time now is 06:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"