Hello,
I created a .Net-DLL including a class which I wanted to use in Excel-VBA. I can reference the .tlb-file in VBA and create a new instance of the class. But I can neither access any members of it nor do I see any properties or methods of the class in the vba-object explorer.
Here is what I have done:
1. Written a simple test-class in VB.Net:
Imports System.Runtime.InteropServices
Public Class clsPerson
Private _name As String
Private _age As Integer
'Needed for COM-interoperability
Public Sub New()
End Sub
<ComVisible(True)> Public Property Name() As String
Get
Name = _name
End Get
Set(ByVal value As String)
_name = Name
End Set
End Property
<ComVisible(True)> Public Property Age() As Integer
Get
Age = _age
End Get
Set(ByVal value As Integer)
_age = value
End Set
End Property
Public Function Description() As String
Return Me.Name & " ist " & Me.Age & " Jahre alt."
End Function
End Class
2. Checked "Make the Assembly visible to COM" in the Assembyinformation-popup-windowof the project-properties..
3. Checked "Register for COM-Interop" in the compile-settings of the project-properties.
4. Built the project somewhere.
5. In Excel-VBA-Editor edited a reference to the newly built .tlb-file.
6. Wrote following test-code in VBA
Sub Test()
Dim p As New clsPerson
p.Name = "f"
End Sub
The clsPerson-Instance gets created, but the line p.Name throws an automation error.
Any idea what goes wrong? Any ideas are welcome.
Thx a lot for your help!
P.S.: Just got the VBA-Editor to show the members by setting the "COM-class"-Property the .NET-Class in Visual Studio to "True". Anyway, an automation-error is still thrown when trying to set a value, eg. for the age-property of the person-class in vba.