Discussion:
How to navigate to a link on an IE page?
(too old to reply)
Herbert Chan
2005-02-12 11:16:29 UTC
Permalink
Hello,

Say I've used script to open www.yahoo.com. How can I navigate to for
example to the first link that include the word "map" in its url?

Set IEObject=CreateObject("InternetExplorer.Application")
If Err.number <> 0 Then
MsgBox "There was a problem starting Internet Explorer."
wScript.Quit
End If
IEObject.Navigate "http://www.yahoo.com"
IEObject.Visible=1
Do while IEObject.Busy
Rem -- wait for window to open --
Loop
'what to put here??

And do I need to set IEObject to nothing at the end of the script?

Thanks.

Herbert
Joe Fawcett
2005-02-12 12:20:13 UTC
Permalink
Post by Herbert Chan
Hello,
Say I've used script to open www.yahoo.com. How can I navigate to for
example to the first link that include the word "map" in its url?
Set IEObject=CreateObject("InternetExplorer.Application")
If Err.number <> 0 Then
MsgBox "There was a problem starting Internet Explorer."
wScript.Quit
End If
IEObject.Navigate "http://www.yahoo.com"
IEObject.Visible=1
Do while IEObject.Busy
Rem -- wait for window to open --
Loop
'what to put here??
And do I need to set IEObject to nothing at the end of the script?
Thanks.
Herbert
Function NavigateLink(Doc, Contains)
Dim colLinks
Dim iIndex
Dim oLink
Set colLinks = Doc.links
For iIndex = 0 To colLinks.count - 1
Set oLink = colLinks(iIndex)
If InStr(oLink.href, Contains) > 0 Then
Call oLink.click() ' Or maybe IEObject.navigate oLink.href depending
on what you need
NavigateLink = True
Exit Function
End If
Next
NavigateLink = False
End Function

And call when document is loaded with:
Call NavigateLink(IEObject.document, "map")

You can set IEObject to nothing but more importantly maybe to IEObject.quit
when finished.
--
Joe (MVP)
Continue reading on narkive:
Loading...