2
votes

I am attempting to create a DLL in VB.NET using Visual Studio 2017. The DLL will be used in VBA in another application. The VB.NET project is a .NET Framework Class Library project.

I've added the *.TLB file as a reference in VBA. I'm only trying to create and use one method in the class library. I'm calling it in VBA using something similar to the following:

Sub MySub()
    Dim TestObj As MyProjectName.MyClassName
    Set TestObj = New MyProjectName.MyClassName
    Call TestObj.MyMethodName(Argument)
End Sub

The code always throws Runtime Error 429 "ActiveX component can't create object" on the following line (from the example above):

Set TestObj = New MyProjectName.MyClassName

This question has been asked before, however most of them are quite old (~10 years) and none of the solutions offered made any difference. I keep finding references to REGASM.EXE. It is my understanding that Visual Studio handles this automatically and that calling this manually isn't necessary when the "Project>Properties>Compile>Register for COM interop" checkbox is checked.

I have followed these instructions to the letter: https://smallbusiness.chron.com/use-net-class-library-excel-vba-40349.html

In addition I tried creating a COM class instead per the answer to the following question: ActiveX component can't create object when using .net class in vba

I've tried at least half a dozen different iterations of this and they all give Runtime Error 429 "ActiveX component can't create object". Is there something I'm missing here? Could it be a version issue somehow? My VS project is targeting .NET Framework 4.7.2.

1
if the application referencing the dll is a lower version of .net that would be an issue. not sure if that is your case or not. - Popo
The application referencing the DLL is a VBA macro in CorelDRAW 2017. - Orion DeYoe
I'm experiencing this same problem, has anyone found a solution to this? - Michael Gordon
@MichaelGordon I never got an answer to this question. I ended up having to pursue a completely different approach to my application. - Orion DeYoe

1 Answers

2
votes

Not sure if my problem is the same as your problem but this is how I fixed my problem:

I think the key issue with what I was doing is I was registering the dll with:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe

When I should have been registering it with:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe

Other than that I followed this StackOverflow Q/A:

Excel 2010 64 bit can't create .net object