声明包含后期绑定字典对象的自定义数据类型



是否可以声明自定义类型具有后期绑定的字典对象作为其元素之一? 例如,在标准模块或类模块中:

Private Type InternalData
sName as String
cSheets as Collection    'cSheets as New Collection
wBook as Workbook
bFiles as CreateObject("Scripting.Dictionary")    'bFiles as New CreateObject("Scripting.Dictionary")
End Type

或者有没有其他方法?请注意,我不想提前绑定字典。

您将处理字典对象,类似于处理工作簿对象的方式。 将字典声明为类型Object,然后在其他地方对其进行初始化。 例如,在表单中,您可以拥有:

Private Type InternalData
sName As String
cSheets As Collection
wBook As Workbook
bFiles As Object
End Type
Public Sub TryIt()
Dim id As InternalData
Set id.bFiles = CreateObject("Scripting.Dictionary")
id.bFiles.Add Key, Value
End Sub

根据评论,以下是使用类的方法。 在类模块中:

Public sName As String
Public cSheets As Collection
Public wBook As WorkBook
Public bFiles As Object
Private Sub Class_Initialize()
Set bFiles = CreateObject("Scripting.Dictionary")
End Sub

然后像以前一样,也许以形式:

Public Sub TryIt()
Dim id As InternalData
id.bFiles.Add Key, Value
End Sub

相关内容

  • 没有找到相关文章

最新更新