Waiting for a web page to load

vmi1839

New Member
Joined
Apr 1, 2003
Messages
39
Is there a way to have a macro wait until a web page has loaded for it to continue? I want the macro to be smart enough to figure out how long to wait based on the web pages status.

I'm trying to grab and copy the web page, but I need it to load first. I have been using the Application.Wait command, but this seems too clumsy and has a tendency to either be too long or not long enough.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Wait for a web page to load into what? Do you mean wait for a web query to finish?

Code:
With Worksheets(1).QueryTables(1) 
   Do While .Refreshing = True 
   Loop 
End With
 
Upvote 0
There are two different ways that I have been doing it:

The first way is as follows:

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "http://www.cnn.com"

The second way looks like this:

ActiveWorkbook.FollowHyperlink Address:="http://www.cnn.com"
 
Upvote 0
This seems to work:

Code:
Sub Test()
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "http://www.cnn.com"
    Do
        If IE.readyState = 4 Then
            IE.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
    MsgBox "Done"
    IE.Visible = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,999
Messages
6,175,889
Members
452,679
Latest member
darryl47nopra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top