ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting Information about Events Seen In the Object Browser (https://www.excelbanter.com/excel-programming/422306-getting-information-about-events-seen-object-browser.html)

[email protected][_2_]

Getting Information about Events Seen In the Object Browser
 
Events are designated in the Object Dictionary by a lightening icon.

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.


Tim Williams

Getting Information about Events Seen In the Object Browser
 
You can declare an object variable "With Events" - this allows you to attach
to the object's events.

Yim

wrote in message
...
Events are designated in the Object Dictionary by a lightening icon.

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.




[email protected]

Getting Information about Events Seen In the Object Browser
 
Here's an exmaple using the BeforeNavigate2 and NavigateComplete2
events;

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, "
wrote:
Events are designated in the Object Dictionary by a lightening icon.

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.



All times are GMT +1. The time now is 10:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com