Re: Loop to load webpage
- From: "Tim Williams" <timjwilliams at gmail dot com>
- Date: Tue, 9 Aug 2005 08:58:11 -0700
Don't have time to look at this at work but can answer one part: how to get
a reference an already open IE window.
The following will find an open IE instance which has a page loaded from a
specified URL (actually it will find any "like URL*")
'************************************
Function GetIE(sLocation As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim retVal As Object
Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
sURL = ""
On Error Resume Next
'check the URL and if it's the one you want then
' assign it to the return value
sURL = o.document.Location
On Error GoTo 0
If sURL Like sLocation & "*" Then
Set retVal = o
Exit For
End If
Next o
Set GetIE = retVal
End Function
'*********************************
You can use it like this
dim ie as object
set ie = GetIE("http://login.yahoo.com")
Tim.
--
Tim Williams
Palo Alto, CA
"Brian Delaney" <bpdelaney@xxxxxxx> wrote in message
news:O0sZyeOnFHA.2916@xxxxxxxxxxxxxxxxxxxxxxx
> Hi Tim,
>
> How can I determine if a page is framed? (I've been viewing the pages'
> HTML code by using View > Source in the IE browser window.)
>
> Here's the whole code
>
> Public Sub Yahoo_Finance()
>
> ' Open Internet Explorer application
> Set ie = CreateObject("InternetExplorer.Application")
>
> With ie
> Visible = True
> ' Go to Yahoo login page
> Navigate
> "http://login.yahoo.com/config/login?.done=http://finance.yahoo.com&.src
> =quote&.intl=us"
>
> ' Loop until the page is fully loaded
> Do Until .ReadyState = 4
> DoEvents
> Loop
>
> ' Make the desired selections on the web page and click the submit
> Button
> Set ipf = ie.Document.all.Item("login")
> ipf.Value = "keepithot9"
> Set ipf = ie.Document.all.Item("passwd")
> ipf.Value = "easier"
> Set ipf = ie.Document.all.Item("login_form")
> ipf.submit
>
> ' Loop until the YF homepage is fully loaded
> Do Until .ReadyState = 4
> DoEvents
> Loop
>
> ' Go to next page within YF
> Navigate "http://finance.yahoo.com/p?v&k=pf_1"
>
> End With
>
> End Sub
>
>
> I discovered this code here on Developersdex (thread: "Re: Web browser
> question").
>
> The weird thing is that when I first tried the code, I didn't have this
> problem. I had misread the form data for the YF login page (didn't see
> that it was POST method), so I substituted
>
> Application.SendKeys "~"
>
> for
>
> ipf.submit
>
> and it worked perfectly a half dozen times. Then when I tried it later
> it always failed. I subsequently changed that line to ipf.submit and the
> login succeeded but since then the homepage doesn't load quickly enough.
> Also, when I step throught the code it works fine which is what leads me
> to believe that it's the loop that's not working right.
>
> A copule other vba-newbie questions perhaps you could help me with too?
>
> If I have a IE browswer window already open (say, with the YF homepage
> already loaded), what code do I use to activate it? AppActivate?
>
> My ultimate goal is to copy the data from the final YF page to a
> spread***. What would be the code to select the contents of the page
> (the whole page is fine as opposed to pinpointing tables, I can extract
> the table data easily once in the spread***) for copying to the
> clipboard?
>
> Finally (= really clueless), how is it that when I post directly to the
> newsgroup, your reply appears on Developerdex but not the newsgroup (new
> to these too)?
>
> Hope the newbie questions aren't too annoying. Thanks very much for any
> help you can offer.
>
> Brian
>
> *** Sent via Developersdex http://www.developersdex.com ***
.
- References:
- Re: Loop to load webpage
- From: Tim Williams
- Re: Loop to load webpage
- From: Brian Delaney
- Re: Loop to load webpage
- Prev by Date: Re: Check for date
- Next by Date: Create Summary ***
- Previous by thread: Re: Loop to load webpage
- Next by thread: VBE(Visual Basic Editor) Keep focus in VBE
- Index(es):