C# class library to use with Excel VBA
-
I have built a class library using VS 2013 C#. It includes an interface to expose all the functions and public properties. It compiles and registers for use as COM visible. I can readily access the functions in the library from VBA. But there seems to be no way to access public properties in the class library with VBA. All the information I find on the web is for simple applications where there are no public properties, only functions. My efforts suggest that accessing public properties in the library is not doable. Is my conclusion correct? If there is a way to achieve it, maybe someone can point me to a resource.
-
I have built a class library using VS 2013 C#. It includes an interface to expose all the functions and public properties. It compiles and registers for use as COM visible. I can readily access the functions in the library from VBA. But there seems to be no way to access public properties in the class library with VBA. All the information I find on the web is for simple applications where there are no public properties, only functions. My efforts suggest that accessing public properties in the library is not doable. Is my conclusion correct? If there is a way to achieve it, maybe someone can point me to a resource.
Might not be quite what you're after, but couldn't you expose the properties by means of (explicit) getter and setter functions? Cheers, Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
Might not be quite what you're after, but couldn't you expose the properties by means of (explicit) getter and setter functions? Cheers, Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
Thanks, Peter. I was hoping to avoid having to add/modify the classes that are built for .Net use with methods and properties. But I have not found any other way to approach it other than the one you suggested. On another tack, is there any software to generate an interface from the methods and properties in a class? I use copy/paste/edit which is time consuming. But I do have lots of time. Microsoft has made it difficult to use .Net with VBA, going in either direction. And it's maddening to try to hook to an open Excel workbook from a .Net application. So I gave this up.
-
Thanks, Peter. I was hoping to avoid having to add/modify the classes that are built for .Net use with methods and properties. But I have not found any other way to approach it other than the one you suggested. On another tack, is there any software to generate an interface from the methods and properties in a class? I use copy/paste/edit which is time consuming. But I do have lots of time. Microsoft has made it difficult to use .Net with VBA, going in either direction. And it's maddening to try to hook to an open Excel workbook from a .Net application. So I gave this up.
With regard to "another tack", I don't know of anything, but then I am merely a tourist in the .NET and C# district. Maybe some of the friendly locals might know. Cheers, Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
With regard to "another tack", I don't know of anything, but then I am merely a tourist in the .NET and C# district. Maybe some of the friendly locals might know. Cheers, Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
I found that Visual Studio has a tool accessible from the context menu to generate the interface. I run into obstacles often when I build a C# library for COM and try to use it in Excel. I have two such libraries with interfaces that appear to be identical in format. One works with Excel, the other does not. However, the one that doesn't work using an interface works OK when I remove the interface. But then nothing is available for VBA intellisense. And the functions don't show in the object explorer with either version. Is there a good book or reference that carefully and fully explains building C# libraries for use with Excel VBA?