473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A problem of invoking C# DLL from VBA

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
Nov 4 '06 #1
3 1483
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!

"Paul" wrote:
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
Nov 8 '06 #2
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.


"Shailen Sukul" wrote:
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!

"Paul" wrote:
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
Nov 8 '06 #3
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!

"Paul" wrote:
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.


"Shailen Sukul" wrote:
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!

"Paul" wrote:
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
Nov 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Prasad | last post by:
We are invoking a SQL DTS component (lets call it Comp1) built by us in another component (Comp2).Comp1 was built by creating the DTS package using the SQL DTS wizard and then saving it as a VB...
6
by: Patrick | last post by:
Following earlier discussions about invoking a .NET class library via ..NET-COM Interop (using regasm /tlb) at...
4
by: Joanna Carter \(TeamB\) | last post by:
I am trying to invoke an event using reflection. ////////////////////// public class Test { public event EventHandler NameChanged; public void CallEvent() {
25
by: MuZZy | last post by:
Hi, I'm currently rewriting some functionality which was using multithredaing for retrieving datasets from database and updating a grid control. I found that the grids (Infragistics UltraGrid,...
2
by: shanmani | last post by:
Hi, I am developing a .NET application which will invoke the methods from different COM / .NET DLLs. While invoking methods from .NET DLLs, I am encountering the following error. I have also...
0
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to...
0
by: balaji krishna | last post by:
Hi, I need to handle the return set from COBOL stored procedure from my invoking Java program. I do not know, how many rows the stored proc SQL fetches.I have declared the cursor in that proc, but i...
2
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
1
by: imranisb | last post by:
Hi, I apologies if this type of question was posted before. I am invoking internet explorer and open the HTTPS website from my c# application like this: System.Diagnostics.Process proc =...
6
by: John O'Flaherty | last post by:
Hello. I have an ms acess database that I use to track my mp3 files. I have included code that lets me select and play files by invoking an mp3 player (Winamp). This is done by using visual basic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.