When I create a C# .Net library (Framework 2.0 and Visual Studio 2005) and expose it to com, it works great from a Visual Basic 6 client but doesn't work from a VB script client (such as Excel).
The error message from Microsoft Visual Basic in Excel is:
Run-time error '-2147024894(800070002)';
File or assembly name TestCallingDotNetFromCom, or one of its dependencies, was not found.
Here's the C# library code:
public interface iTestStuff
public class TestStuff : iTestStuff
public string SayHello()
return "Hello there";
It's complied as a strong-name assembly with the Make assembly COM-Visible checkbox checked. I copy the library to another machine (XP Professional) and register it as:
regasm TestCallingDotNetFromCom.dll /tlb
This creates the type library and registers both the type library and the library. Then I copy the library to the GAC.
I open up the Visual Basic editor in Excel (XP version) and set a reference to TestCallingDotNetFromCom. Examining it from the Object Browser, it looks fine. I add a module with the code:
Dim obj As New TestCallingDotNetFromCom.TestStuff, _
s As String
s = obj.SayHello
Set obj = Nothing
When I run the code I get the error mentioned above.
HOWEVER, I use Visual Basic 6 to create an executable with EXACTLY the same code, then copy the exe to the test machine and run it, it works perfectly!
What's the difference between calling a com callable .Net library from Visual Basic 6 and Visual Basic script in Excel?
Appreciate any help!