RE: "Object Required" error when calling .Net DLL



Akash,

I have not done this before so I'm just guessing. But I think the problem
is that you have the Value property declared as an object

Property Value() As Object

and in your VBA code, you try to assign a string value to it which is not an
object.

CC.Value = "abcd"


Maybe you can change the Value Property to String? Or assign an object to
the Value property when you use it.. For example, will it give an error when
you try something like this?

Set CC.Value = CreateObject("Excel.***")


--
Hope that helps.

Vergel Adriano


"akash" wrote:

I have a simple .Net 2.0 class which I am trying to access from Excel
(Office XP).

<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IComClass
Property Value() As Object
End Interface

<ClassInterface(ClassInterfaceType.None)> _
Public Class ComClass
Implements IComClass
Public Property Value() As Object Implements IComClass.Value
Get
Return Me._Value
End Get
Set(ByVal value As Object)
Me._Value = value
End Set
End Property
Private _Value As Object

Public Sub New()
Me._Value = 1234
End Sub
End Class

I have produced the .tlb, registered the class and added the
apprioriate reference in VBA. However, when I try to run the following
code I get an "object required" error at the line ' CC.Value = "abcd"
'

Dim CC As New ComClass
MsgBox (CC.Value)
CC.Value = "abcd"
MsgBox CC.Value

Any idea what I am missing?

Thanks
Akash


.


Loading