Internet Explorer event DocumentComplete does not fire

nze123

New Member
Joined
Jan 26, 2016
Messages
1
Hello folks

I am struggling to use events with IE automation from an Excel workbook, to feed some data from a web server into Excel.
The queried page takes very long, and I would like the user to initiate the query with IE to obtain the data, then once the web page is complete, return control to my Excel book to fetch the data and perform some post-processing.
I first started with an IE object with :
Code:
Do Until .readyState = 4
    Application.Wait (Now + TimeValue("00:00:01"))
   DoEvents
Loop
The problem is, the loop will hold Excel waiting until the page is ready, and I cannot use Excel as long as the web query runs.

To perform asynchronously, I started investigating the event handlers, which I am not familiar with

I tried the following code in ThisWorkbook :
Code:
Private WithEvents IE As SHDocVw.InternetExplorer
            
Public Sub invokeIE()
  Set IE = New SHDocVw.InternetExplorer
  IE.Visible = True
  IE.Navigate "http://www.google.com"
End Sub
            
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
   MsgBox "Document complete" & vbCrLf & URL
End Sub

However it seems the event DocumentComplete will never fire??

Any idea what I am doing wrong here ?
Same applies with IE.Navigate2, and with a simple InternetExplorer object (without SHDocVw prefix)

I am running Windows 7 SP1 and Office 2010
References to "Microsoft Internet Controls" & "HTML Object Library" are activated

Thanks in advance
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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