Discussion:
.Net Class Library Collections for COM consumption.
(too old to reply)
bob
2008-03-27 18:17:20 UTC
Permalink
I am in the process of creating a class library that is intended for
consumption by VBA in an Excel Workbook. The thought being that this
will create a transition period as we migrate from VBA based solutions
to .Net solutions.

I have not done any COM development before and I am having a couple of
problems. Please forgive me if I have overlooked something simple.

I have explicitly defined the interface for the CCW for each of the
classes I want to be visible, I would like to be able to pass some
collections back into the VBA but I have not been able to define them
in the interface so they are visible in the object browser of the VBA
editor.

Spefically, I have been using List<T> in the C# code, but I willing to
convert them to whatever they need to be so they are recognizable
within the VBA. Does anyone know how I can define my data lists so
they are recognizable with in VBA?

I also realize that another option would be to wrap the list in a sub
class with an IEnumerable interface, but I'm not sure if that would
allow me pass my objects into a collection on the VBA side of the
project. Will presenting the IEnumerable interface allow me to loop
through objects in a collection class from VBA?

I also made the mistake that for awhile I was testing using the
AutoDual attribute to present the class interface, I have since gone
back and created an explicit interface for everything, but I still get
some strange behavior within the VBA editor of Excel. The object
browser will report the correct methods, but the auto complete /
syntaz highlighting in the code window tells a different story and
will contain methods and properties from another class. Will adding a
DispId attribute to the interfaces fix this or is something more
drastic required? Also, is the DispID associated with the interface
or the property / method within the interface?

Sorry about all of the questions and thanks in advance for any help.
Juan Bautista
2011-06-09 20:36:38 UTC
Permalink
This worked for me.

http://stackoverflow.com/questions/6231995/accessing-net-collection-in-vb6
Post by bob
I am in the process of creating a class library that is intended for
consumption by VBA in an Excel Workbook. The thought being that this
will create a transition period as we migrate from VBA based solutions
to .Net solutions.
I have not done any COM development before and I am having a couple of
problems. Please forgive me if I have overlooked something simple.
I have explicitly defined the interface for the CCW for each of the
classes I want to be visible, I would like to be able to pass some
collections back into the VBA but I have not been able to define them
in the interface so they are visible in the object browser of the VBA
editor.
Spefically, I have been using List<T> in the C# code, but I willing to
convert them to whatever they need to be so they are recognizable
within the VBA. Does anyone know how I can define my data lists so
they are recognizable with in VBA?
I also realize that another option would be to wrap the list in a sub
class with an IEnumerable interface, but I'm not sure if that would
allow me pass my objects into a collection on the VBA side of the
project. Will presenting the IEnumerable interface allow me to loop
through objects in a collection class from VBA?
I also made the mistake that for awhile I was testing using the
AutoDual attribute to present the class interface, I have since gone
back and created an explicit interface for everything, but I still get
some strange behavior within the VBA editor of Excel. The object
browser will report the correct methods, but the auto complete /
syntaz highlighting in the code window tells a different story and
will contain methods and properties from another class. Will adding a
DispId attribute to the interfaces fix this or is something more
drastic required? Also, is the DispID associated with the interface
or the property / method within the interface?
Sorry about all of the questions and thanks in advance for any help.
Juan Bautista
2011-06-09 20:43:27 UTC
Permalink
This worked for me:

http://stackoverflow.com/questions/6231995/accessing-net-collection-in-vb6
Post by bob
I am in the process of creating a class library that is intended for
consumption by VBA in an Excel Workbook. The thought being that this
will create a transition period as we migrate from VBA based solutions
to .Net solutions.
I have not done any COM development before and I am having a couple of
problems. Please forgive me if I have overlooked something simple.
I have explicitly defined the interface for the CCW for each of the
classes I want to be visible, I would like to be able to pass some
collections back into the VBA but I have not been able to define them
in the interface so they are visible in the object browser of the VBA
editor.
Spefically, I have been using List<T> in the C# code, but I willing to
convert them to whatever they need to be so they are recognizable
within the VBA. Does anyone know how I can define my data lists so
they are recognizable with in VBA?
I also realize that another option would be to wrap the list in a sub
class with an IEnumerable interface, but I'm not sure if that would
allow me pass my objects into a collection on the VBA side of the
project. Will presenting the IEnumerable interface allow me to loop
through objects in a collection class from VBA?
I also made the mistake that for awhile I was testing using the
AutoDual attribute to present the class interface, I have since gone
back and created an explicit interface for everything, but I still get
some strange behavior within the VBA editor of Excel. The object
browser will report the correct methods, but the auto complete /
syntaz highlighting in the code window tells a different story and
will contain methods and properties from another class. Will adding a
DispId attribute to the interfaces fix this or is something more
drastic required? Also, is the DispID associated with the interface
or the property / method within the interface?
Sorry about all of the questions and thanks in advance for any help.
Post by Juan Bautista
This worked for me.
http://stackoverflow.com/questions/6231995/accessing-net-collection-in-vb6
Loading...