Create Class Module using late binding

M

Mariano B.

I have a code that creates a new workbook that has some macros within. One of
the is an event handler (I want some stuff to happen everytime a Pivot-Table
is updated).
I did it using early binding and it worked for me nut not to most of the
users. So I tried to switch to late binding.
I only need to know how to create a new class module.
Here is an example of what i did:

Sub Test1()
Dim module As Object
Set module = ThisWorkbook.VBProject.VBComponents.Add(1)
module.Name = "hola"
module.CodeModule.AddFromString ("'TESTING")


ThisWorkbook.VBProject.VBComponents.Item("ThisWorkbook").CodeModule.AddFromString ("'Just to see it works")
End Sub


Does anybody know how to get it done?
Thanks
 
M

Mariano.

Thanks, I saw that page (in fact, it helped me create the first version of
my app), but it doesn't say anything about class modules .

Greetings
 
M

Mariano.

Got it, all I hat to do is create a class module somewhere else and export it
as a .cls file and then import it on the new workbook like this:

Sub Test1()
Dim clsName As String

clsName = "C:\SRC\XMedios\PvtUpdt.cls"

ThisWorkbook.VBProject.VBComponents.Import fname

End Sub


Chip Pearson seems to be the answer to everything.
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top