A problem of invoking C# DLL from VBA

G

Guest

I have a problem of invoking my C# DLL from my VBA code.

I have created the C# component, my code is looking like this:

public class Class1 {
public Class1() {
}
public int TestMethod(int i, int j) {
return i + j;
}
}

and I compiled using Visual studio for C# 2005 (.NET 2.0) with the
"Register for COM interop" option and have the ComVisible(true)
assembly attribute set.

Then I have set the reference to "testdll.tlb" in my Excel VBA
environment.
And my VBA code here

Sub test()
Dim a As testdll.Class1
Set a = New testdll.Class1
End Sub

The problem is.. everytime when I run the macro it complains at the 2nd
line of my VBA code:

"File or assembly name testdll, or one of its dependencies, was not
found."

I spent a day but still unable to figure out which step I was
missing....

If anyone know the answer, please help~~~~

Thank you very much.

Paul
 
G

Guest

The error message seems pretty self explanatory. It seems that your .Net dll
needs a reference to another dll and that has not been deployed with your
main .Net dll. Have a look at the .Net project under references and find out
any third party dlls that are there. You will have to deploy these extra dlls
with your .Net dll for it to work.

Good luck!
 
G

Guest

Thanks for the answer..

But first of all, is .NET dll can be used as a "Reference" in ordinary Excel
VBA environment?? Just the machine deployed with .NET framework is okay right?


Thanks.
 
G

Guest

Sorry I did not read your whole post. It seems that you are not using any 3rd
party dlls. So the next question would be, did you register the .Net dll
using Regasm?

And yes, you will need the .Net framework on the machine with the Excel VBA
Env.

Good luck!
 

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