所有
我在VS2005中写道,面对面应该是一个相对简单的DLL,它允许我在Excel 2007中调用时构建自定义对象列表。为此,我有一个列和列类。如图所示,Columns是Column对象的列表。相关类定义如下:
<Guid("1CD713EC-D140-4e8b-92D7-99E098694A85")> _
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IColumn
Property Name() As String
End Interface
<Guid("6B146BF8-E905-4ed1-84D5-147B1A510AE3")> _
<ClassInterface(ClassInterfaceType.None)> _
Public Class Column
Implements IColumn
Private _name As String
Public Sub New()
MyBase.new()
End Sub
Public Property Name() As String Implements IColumn.Name
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
<Guid("C2C98A9B-DF7B-4ce1-9F48-EF2B0E63A8E8")> _
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IColumns
Sub Add(ByVal col As Column)
End Interface
<Guid("CA76EAF0-1B87-402a-8720-933EDFA0CAE4")> _
<ClassInterface(ClassInterfaceType.None)> _
Public Class Columns
Inherits List(Of Column)
Implements IColumns
Public Sub New()
MyBase.New()
End Sub
Public Overloads Sub Add(ByVal col As Column) Implements IColumns.Add
col.Name = col.Name.ToUpper
MyBase.Add(col)
End Sub
End Class
以下代码在VS2005中按预期工作:
Dim col As Column
Dim cols As New Columns
col = New Column
col.Name = "DefType"
cols.Add(col)
但是,当使用VBA从Excel中调用时:
Dim col As PiMdbManager.Column
Dim cols As PiMdbManager.Columns
Dim cnt As Integer
Dim colName As String
head = header.Value
For cnt = 0 To header.Count - 1
colName = header(1, cnt + 1)
If colName <> "" Then
Set col = New PiMdbManager.Column
col.Name = header(1, cnt + 1)
cols.Add (col)
End If
Next cnt
'cols.Add(col)'行生成错误'对象不支持此属性或方法'。 .Add方法在VBA中通过intellisense可见。
有人可以向我解释这里发生了什么,以及我如何能够实现我想要做的事情。
亲切的问候
Paul J。
答案 0 :(得分:0)
尝试删除cols.add (col)
中VBA中的括号,使其如下所示:cols.Add col
或者您可以使用“来电”关键字:
Call cols.Add (col)