My C# library (.net 4.5.2) code looks like this:
namespace HelloWorld
{
public class Hello
{
public string HelloUser(string name)
{
return "Hello, " + name;
}
}
}
I have made the assembly COM visible in AssemblyInfo.cs file using the following code:
[assembly: ComVisible(true)]
I added the reference to the dll in VBA code via Tools ->References and when trying to use the same in excel vba, I am getting Run-time error: 429 (ActiveX component can't create object). What's wrong with my code/call:
Excel VBA (2013)
Option Explicit
Sub tester()
Dim message As String
Dim User As String
User = "Ronnie"
Dim obj As New HelloWorld.Hello
message = obj.HelloUser(User)
End Sub
UPDATE
After adding reference via Toos ->References and checking the status using F2

UPDATE #3 Updated the VBA code and still no success. This time the error is:
Run-time error: 429 (ActiveX component can't create object)
staticmight be for this though, and you might want to decorate theHelloclass with appropriate attributes.Declareit, you go Tools > References... and then browse to locate the type library, which you add as a reference. Then hit F2 to get to the VBE's object browser and see if there's aHelloWorldlibrary loaded, and whether it contains aHelloclass with aHelloUserfunction. If not, you have a problem. If so, then you use it in VBA like any other referenced type library.