Is there a way to tell if an Event has fired?
Example.
Check the "Microsoft Internet Controls" reference library and check
out the WebBrowser object - it has an event called DownloadComplete.
So if I have:
Set IE = CreateObject("InternetExplorer.Application")
' Same as Set IE = new WebBrowser()
IE.Visible = True
IE.navigate "http://www.mysite.com"
Can I see if DowloadComplete fired?
Can I attach code that executes when DownloadComplete fires?
BTW, I see there is a Busy property which can be used to see when the
download is complete - but I'd still like to learn about capturing
events.
Thanks.
Yim
<gimme_this...@yahoo.com> wrote in message
news:1d420f5d-0d01-4def...@p23g2000prp.googlegroups.com...
In a class module named "clsIEEventHandler":
Option Explicit
Public WithEvents InternetExplorer As SHDocVw.InternetExplorer
Private mboolNavIsComplete As Boolean
Friend Property Get NavigationIsComplete() As Boolean
NavigationIsComplete = mboolNavIsComplete
End Property
Private Sub Class_Terminate()
Set Me.InternetExplorer = Nothing
End Sub
Private Sub InternetExplorer_BeforeNavigate2(ByVal pDisp As Object, _
ByRef URL As Variant, ByRef Flags As Variant, _
ByRef TargetFrameName As Variant, ByRef PostData As Variant, _
ByRef Headers As Variant, ByRef Cancel As Boolean)
'Fires before navigation
mboolNavIsComplete = False
End Sub
Private Sub InternetExplorer_NavigateComplete2(ByVal pDisp As Object,
_
ByRef URL As Variant)
'Fires when navigation is complete
MsgBox "Navigation completed"
mboolNavIsComplete = True
End Sub
In a standard code module:
Option Explicit
Sub TestIEEventHandler()
Dim objIE As SHDocVw.InternetExplorer
Dim objIEEvents As clsIEEventHandler
Set objIE = New SHDocVw.InternetExplorer
Set objIEEvents = New clsIEEventHandler
Set objIEEvents.InternetExplorer = objIE
With objIE
.Visible = True
.Navigate "http://www.DailyDoseOfExcel.com"
End With
'Ensure that navigation completes before
'the event handler is destroyed
Do While Not objIEEvents.NavigationIsComplete
DoEvents
Loop
'Destroy objects
Set objIEEvents = Nothing
Set objIE = Nothing
End Sub
As you see in the example you can use a class module to trap events of
objects. As Tim says use the With Events statement.. The
DowloadComplete even probably fires when a file has been downloaded
(just guessing, I'm not familiar with the InternetExplorer object
model.
best regards
Peder Schmedling
On Jan 12, 6:58 am, "gimme_this_gimme_t...@yahoo.com"