.NET componant from COM componant  
Author Message
kokain





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

I have a dll file from a .NET application that I want to reference from Excel-VBA. VBA won't let me reference it. I followed instructions and ran tlbexp.exe then regasm.exe and then gacutil.exe and everthing said it worked succesfully. Since I don't know much about programming I can't really say what these things did. I suppose they created and registered a type library from the dll file.

The problem is when I reference the new tlb file with vba I can't get all of my functions. I can see all of the classes ( there are like 50) but only two of them show me the subs, properties and functions.

Is there anyway to reference a .NET dll file with VBA

I want to use VBA because I already have a fairly large program that uses an old version of the new library. All I want to do is reference the new dll and add a few functions.

If none of this makes sense, please let me know and I will TRY to go more in depth.

HELP!!



.NET Development37  
 
 
nobugz





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

Try applying the ClassInterface(AutoDual) attribute to the class. You can use the OleView tool in the Common7\Tools\Bin folder to look at the .TLB file and see what is getting exported. Use View + Typelib.



 
 
kokain





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

I don't have OleView. I am not sure what you mean by "getting exported". I am not very good with all of this programming stuff.
 
 
George Breedlove





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

Did you make your .Net library viewable to COM

You can either set the ComVisible attribute in your assemblyinfo.cs file, or modify your project settings. In Visual Studio 2005 this is accomplished by selection the application tab of your project's properties. Then, click on the 'Assembly Information' button. Finally, select the checkbox 'Make Assembly Com-Visible'.

Alternatively, you can elect to manually set the ComVisible attribute to control specific types you would like to make available to VBA.

ComVisible usage:

[ComVisible(true)]

class SomeClass

{

}

Hope this helps...



 
 
kokain





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

I wish I could. I don't have the project, just the application (build ). I might be able to get the project files, but I think that guy got fired. I did start from scratch and gave-up. It would take me too long to re-write all of my old program in 2005 since I used cells and no form in VBA.

While I am asking difficult questions, can I edit a dll This one I want to reference in VBA (the new one) is very dirty. There is about 50 classes with 200 functions, 100 properties and some enums ext... then for no reason there are duplicates in different classes. It was written and re-written many times, I want it clean.

I appreciate the help from everyone, remember to talk to me like a idiot, and don't be afraid to tell me to give-up and get someone else to do this.


 
 
nobugz





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

Get out now. Run, man, run!



 
 
mikn





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

Assuming that you still have access to VS2005, and that you're feeling desperate, you could trying creating a COM Interop enabled wrapper for the parts of the dll you want to use.

Although VBA can't access all of the content of the dll, a new VS2005 class library project should be able to access all of the public components. Hopefully, since you could pick and choose which components to expose on your wrapper, it would allow you to introduce some of the cleanness you're looking for as well.

It's not ideal, 'cos it sound like you really need a re-write, but it might be a viable workaround in the interim assuming there isn't a hole in the idea I've missed


 
 
Jaimi





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

If you have no access to the source, you may want to try to recover it using Reflector and the File Disassembler: http://www.aisto.com/roeder/dotnet/

I have had good results with this when I lost the code for one project.


 
 
TimDinh





PostPosted: .NET Base Class Library, .NET componant from COM componant Top

Have you try using ComVisible attribute and give it a GUID