Say I have a .NET project to compile to a class library (.DLL). Here is all the code in the library:
Code:
Public Class GetString
Public Function GetTestString() As String
Return "Test String"
End Function
End Class
In the build options, I have selected the library to be Registered for COM Interop. After compiling the project, I get both GetString.dll and GetString.tlb in the \bin folder.
Now in Excel I open a new book. Go to the Vb Editor and add a reference to the GetString.tlb file in the \bin folder of my .NET solution. I then add VBA module and I put the following code:
Code:
Public Sub getStr()
Dim str As New GetString.GetString
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Range("A1").Value = str.GetTestString()
End Sub
Compile -> Save. When I run the macro, everything works perfect! The string is successfully placed in the appropriate cell.
But NOW the part that has confused and frustrated me for a long time. I now take the Excel worksheet, the GetString.dll, and the GetString.tlb file and put them on another computer. The other computer does have .NET installed by the way. When I run the macro, I get the following error: Run-time error '429': ActiveX component can't create the object.
This problem is a much more simplified version of what I am actually dealing with. But If someone could PLEASE tell me the exact steps to take to get this macro to work on a PC other than my own development PC, I would be very greatful.
I *think* that should do it. When compiling, it will auto register it on the development machine. But for deployment, you have to tell the system where to find the files at.
Thanks so much for the reply. I have tried this in the past and I get an error. When I run Regsvr32 "PATH_TO_TLB\GetString.tlb", I get the following message:
"PATH_TO_TLB\GetString.tlb" is not an executable file and no registraion helper is registered for this file type.