ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Class module creating OLEObject (https://www.excelbanter.com/excel-programming/306629-class-module-creating-oleobject.html)

Erich Neuwirth

Class module creating OLEObject
 
I recorded the following macro, and it works.
-=-
Sub Macro1()
Dim ooo As Object
Set ooo = ActiveSheet.OLEObjects.Add(Filename:= _
"C:\Documents and Settings\neuwirth\My Documents\Watermark.pdf", _
Link:=False , DisplayAsIcon:=False)
End Sub
-=-

Now I created a new class module named myobj
which contains

-=-
Dim WithEvents oleobj As OLEObject

Sub Class_Initialize()
Set oleobj = ActiveSheet.OLEObjects.Add(Filename:= _
"C:\Documents and Settings\neuwirth\My Documents\Watermark.pdf", _
Link:=False , DisplayAsIcon:=False)
End Sub
-=-

Then I defined a macro

-=-
Sub testit()
Dim mypdf As myobj
Set mypdf = New myobj
End Sub
-=-


testit does not run, I get an error
Run time error 459
Object or class does not support the set of events.

I do not understand this.
Can anybody help me?


All times are GMT +1. The time now is 12:11 PM.

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