Hooking into Internet Explorer events ?

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,577
Office Version
  1. 2016
Platform
  1. Windows
I am creating a new instance of IE via the CreateObject Function ie: using late binding .

The CreateObject function returns a reference to the newly created IE application through which one can access all the IE Objects, Properties and Methods from our project. So far so good.

Now we regards to automating the IE Events, we could easily achieve the above if we were using Early binding by adding to our project a reference to the IE object library and using the WithEvents keyword.However we don't have a reference to the IE object library so we cannot use WithEvents .

So the question is : How can we hook into the IE events from Excel without first adding a reference to the IE library ??

By extension, I would like to know if there is a way of hooking into other application events such as MsWord,PowerPoint etc without first adding a refenrence to their respective libraries .

Regards.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Applications don't throw events. COM throws the events. If you have Internet Explorer then you have the ability to early bind. The component object model is built into the executable just as it is in Excel. Why are you finding it neccesary to late bind?
 
Upvote 0
Applications don't throw events. COM throws the events. If you have Internet Explorer then you have the ability to early bind. The component object model is built into the executable just as it is in Excel. Why are you finding it neccesary to late bind?

Thanks Tom. I am just curious to know if there is a workaround for the purposes of learning . Also, if one was to distribute their project it would be nice to avoid the complier erroring out at the WithEvents dclaration if the IE COM library was missing on the target machine .

Regards.
 
Upvote 0
VbScript has a method to raise events. VbScript cannot early bind so there is a round about way to raise events on late bound references but it has been several years since I have used it. Maybe a search in that direction will lead to something.
 
Upvote 0
If IE is on the target machine then COM is standard in the install. The browser helper objects are COM based so it's integrated into IE.
 
Upvote 0
VbScript has a method to raise events. VbScript cannot early bind so there is a round about way to raise events on late bound references but it has been several years since I have used it. Maybe a search in that direction will lead to something.

Yes. I was aleardy looking on how to raise late bound events by WScript . I am just trying to figure out how to get a pointer to the WScript root object so I can then Its CreateObject Method and continue from there.

It would be very interesting to see how/if this can be implemented within Excel !

Regards.
 
Upvote 0
Hi Tom.

During my search for how to use VBScript to sink server's events i found this which should work but doesn't !

This runs from a VBS and is supposed to create a new Excel instance and monitor the execl application _SheetChange event.

Code:
Dim myExcel,myWorkbook
Set myExcel=WScript.CreateObject("Excel.Application","excel_")
Set myWorkbook=myExcel.Workbooks.Add()
myExcel.Visible=TRUE
myExcel.EnableEvents=TRUE
 
Sub excel_SheetChange(ByVal Sh, ByVal Target)
WScript.Echo "Sheet Change: Sheet=" & Sh.Name & "Range=" & _
 Target.Row & "," & Target.Column
End Sub

Can you shed some light on why this doesn't work. ?

Regards.
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

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