Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel
Using .net COM Interop from Excel Using .net COM Interop from Excel
Using .net COM Interop from Excel
Go Back  Xtreme Visual Basic Talk > > > Using .net COM Interop from Excel


Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2011, 12:53 PM
Flying_carlos Flying_carlos is offline
Newcomer
 
Join Date: Oct 2010
Posts: 2
Default Using .net COM Interop from Excel


I Programe a COM Library in VS2008 to use in Excel , but I'm stuck with an error that I don't understand.

I use this two classes , that compile and register OK. One Class QBitems return a nongeneric collection of QBItem but when I tried to use the Add and/or Remove Method, I receive the following error in Excel VBA :

Run-time Error '438': Object doesn't support this property or method.

I added a class (SImpleClass) in the library and I called from VBA it returned the QItems collection without problem.

NEW: When I replace the QBItem object with a string in the Collection QBItems everytthing works OK. It looks like interface doesn't like to pass an object like QBitem class
Excel/VBA:
Code:
Code:
Sub Pru()

Dim obj As New CollectionCOMClass.SimpleClass

Dim Itms As New CollectionCOMClass.QBItems

Dim Itm As New CollectionCOMClass.QBItem

 Itm.Name = "CC"

Itm.Price = 40

Itms.Add1 (Itm)    '  This Don't Work

Set Itms = obj.GetCollection         'This Work OK

MsgBox Itms.Count 'This Work OK 

For n = 0 To Itms.Count - 1 

MsgBox Itms.Item(n).Price 'This Work OK

Next

End Sub
Any ideas??

This the Library :
Code:
Imports System.Collections
Imports System.Runtime.InteropServices
Imports System.Collections.ObjectModel
Imports System.Collections.Generic

<Guid("0C5F0D44-125A-4d69-A7BB-AF545C882E9F"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> <ComVisible(True)> _
Public Interface _QBItem
  <DispId(1)> Property Name() As String
  <DispId(2)> Property Price() As Double
End Interface

<Guid("6E41960E-E779-4ea6-B401-7CF779302478"), ClassInterface(ClassInterfaceType.None), ProgId("QBItem")> <ComVisible(True)> _
Public Class QBItem
  Implements _QBItem

  Private mName As String
  Public Property Name() As String Implements _QBItem.Name
    Get
      Return mName
    End Get
    Set(ByVal value As String)
      mName = value
    End Set
  End Property

  Private mPrice As Double
  Public Property Price() As Double Implements _QBItem.Price
    Get
      Return mPrice
    End Get
    Set(ByVal value As Double)
      mPrice = value
    End Set
  End Property
End Class

<Guid("2B4276B5-D99C-4a11-A9B4-10E2E0932021"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> <ComVisible(True)> _
Public Interface _QBItems
  <DispId(1)> ReadOnly Property Count() As Integer
  <DispId(2)> Sub Add1(ByVal Item As QBItem)
  <DispId(3)> Sub Remove(ByVal index As Integer)
  <DispId(4)> ReadOnly Property Item(ByVal index As Integer) As QBItem
End Interface


<Guid("7D5389A0-4A5B-4de5-B6DC-7452E11C9032"), ClassInterface(ClassInterfaceType.None), ProgId("QBItems")> <ComVisible(True)> _
Public Class QBItems
  Inherits System.Collections.CollectionBase
  Implements _QBItems

  Public Sub Add1(ByVal Item As QBItem) Implements _QBItems.Add1
    List.Add(Item)

  End Sub

  Public Sub Remove(ByVal index As Integer) Implements _QBItems.Remove
    If index > Count - 1 Or index < 0 Then
      Console.WriteLine("Can't add this item")
    Else
      List.RemoveAt(index)
    End If
  End Sub

  Public Shadows ReadOnly Property Count() As Integer Implements _QBItems.Count
    Get
      Return MyBase.Count
    End Get
  End Property
  Default Public ReadOnly Property Item(ByVal index As Integer) As QBItem Implements _QBItems.Item
    Get
      Return CType(List.Item(index), QBItem)
    End Get
  End Property

End Class
<Guid("EB66344D-F085-4b36-8114-15F9B8D9E637"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> <ComVisible(True)> _
Public Interface _SImpleClass
  <DispId(1)> Function GetCollection()
End Interface

<Guid("599C989B-ADB6-4932-80B8-9021B8197733"), ClassInterface(ClassInterfaceType.None), ProgId("SimpleClass")> <ComVisible(True)> _
Public Class SimpleClass
  Implements _SImpleClass
  Public Function GetCollection() Implements _SImpleClass.GetCollection
    Dim Itm As New QBItem
    Dim ItmS As New QBItems
    Itm.Name = "AA"
    Itm.Price = 10
    ItmS.Add1(Itm)
    Itm = New QBItem
    Itm.Name = "BB"
    Itm.Price = 20
    ItmS.Add1(Itm)

    Return ItmS
  End Function
End Class
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel Using .net COM Interop from Excel
Using .net COM Interop from Excel
Using .net COM Interop from Excel
 
Using .net COM Interop from Excel
Using .net COM Interop from Excel
 
-->