Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Java Script

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bodhisatvaofboogie - 24 Sep 2007 14:46 GMT
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!!!
Tim Williams - 25 Sep 2007 07:29 GMT
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

> How does one automate Internet Explorer when a web page has Java Script in
> it?
[quoted text clipped - 46 lines]
> of IE that is already open, instead of opening a new one?   THANKS
> AGAIN!!!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.