Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > No members available when using .NET assembly in Excel VBA
 

No members available when using .NET assembly in Excel VBA

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.
Feraud  Saturday, November 14, 2009 12:54 PM
Hello,

finally solved the issue by myself. Problem was my Office 2003 was not up-to-date. I updated it with SP3 & a special fix for COM-Interoperability-Issues (http://www.microsoft.com/downloads/details.aspx?FamilyId=1B0BFB35-C252-43CC-8A2A-6A64D6AC4670&displaylang=en)

Now the Automation error is gone.
  • Marked As Answer byFeraud Sunday, November 15, 2009 2:18 PM
  •  
Feraud  Sunday, November 15, 2009 2:18 PM
Hello,

finally solved the issue by myself. Problem was my Office 2003 was not up-to-date. I updated it with SP3 & a special fix for COM-Interoperability-Issues (http://www.microsoft.com/downloads/details.aspx?FamilyId=1B0BFB35-C252-43CC-8A2A-6A64D6AC4670&displaylang=en)

Now the Automation error is gone.
  • Marked As Answer byFeraud Sunday, November 15, 2009 2:18 PM
  •  
Feraud  Sunday, November 15, 2009 2:18 PM

You can use google to search for other answers

Custom Search

More Threads

• Why does 'ToString' marshal to COM as a property instead of a function?
• Access service on remote computer
• interop between vba and vb
• Where to put app.config?
• Need some help about a vb6 program i made and starting it in vb2008
• Spelling and Grammar check in VB .net 2008
• Interop Forms Toolkit 2.0 Usercontrol in Access 2003 Problem
• Create Outlook advanced find in VS2003
• DataLogging - ActiveX Errors on Vista, but not on XP, using VB6 upgraded to VS2008
• MSComctlLib.Button property Button.Top was not upgraded