Java Script

B

bodhisatvaofboogie

How does one automate Internet Explorer when a web page has Java Script in
it?
I have working code for a macro within Excel to automatically do things for
regular HTML, and I can find names of boxes within the source for that.
However, when I come across things with Java Script, I have NO idea how to
find the names of links/text boxes/check boxes or even how to activate them.
I've seached through a ton of forums for automate IE, or IE automation, or
Java Script, etc, and have come up with no examples of code for it at all, or
even how to find the links/boxes for activating them. Perhaps there has been
some stuff, but I'm no programmer, so pretty straight forward examples or
instructions may be necessary. Any help would be VERY appreciated, Thanks!!!

Here is an example of the working code for regular HTML

Sub WORKING()
Dim IE
Dim IPF
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "http://weather.noaa.gov/weather/shorttaf.shtml"
Do Until Not .Busy
DoEvents
Loop
Set IPF = IE.Document.all.Item("mw0")
IPF.Value = "LEVC"
Set IPF = IE.Document.all.Item("SUBMIT")
IPF.Value = "submit"
IPF.Click
Do Until Not .Busy
DoEvents
Loop
End With
With IE
.Visible = True
End With
IE.Quit
End Sub

Is there anything applicable like this for Java as well, or is it more
complicated?

PART 2: Also, is there any way to just have the macro utilize an instance
of IE that is already open, instead of opening a new one? THANKS AGAIN!!!
 
T

Tim Williams

If the web page you're trying to automate is created in part by javascript
then you need to look at the genrated source and not what you get the normal
way using "view source".

One way to do this is to use a "bookmarklet" to show you the final source
and base your automation on what you see there.
See the "generated source" example here:
https://www.squarefree.com/bookmarklets/webdevel.html

In order to use an existing IE window you could try something like:

'****************************************************
'Find an IE window with matching location and return it
' Assumes no frames.
Function GetIE(sAddress As String) As Object

Dim objShell As Object, objShellWindows As Object, o As Object
Dim retVal As Object, sURL As String


Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

For Each o In objShellWindows
sURL = ""
On Error Resume Next
sURL = o.document.Location
On Error GoTo 0
If sURL <> "" Then
If sURL Like sAddress & "*" Then
Set retVal = o
Exit For
End If
End If
Next o

Set GetIE = retVal
End Function
'*******************************

Modify your code to something like
....
Set IE = GetIE("") 'blank URL matches any open IE window
If IE Is Nothing Then
Set IE = CreateObject("InternetExplorer.Application")
End If
.....


Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top